mysqli's People
Forkers
zefengjiang imefisto tioncico xiaocaigua evalor willove ayhome hanwenbo shrrung chenjing0521 yaphats wjcgithub julibo cxyangs song-steven manlinup sunnychenkang lpong f2h2h1 huizhang-easyswoole player626 luffyqaq giantwu xuesilf lys-organiza ajunlonglive phper-ordinarymysqli's Issues
是否支持数据库批量插入?
您好
请问是否支持数据库批量插入?
建议希望能增加sql语气注释的方法,如mycat /*!mycat:db_type=master*/ 强制走写
RT:
添加这个功能还是很实用
raw参数为数字型的字符串时会错误
在 replacePlaceHolders函数中,使用了is_numeric来判断参数类型,没有使用gettype拿到的类型。看了下好像改成is_int和is_double了,没问题了
QueryBuilder使用union时 构建的SQL语句 union前面缺少空格 导致SQL执行错误
where null查询会查不到数据
- where('time', null) // time = null ×
- where('time', null, '=') // time = null ×
- where(['time' => null]) // time = null ×
- where('time', null, 'is') // time is null √
- where('time is null') // time is null √
以上1-3常用的方式会被解析成错误的where条件, 导致查询null值失败
mysqli的事务怎么写
mysqli的事务怎么写
没有示例,尝试直接使用都是没有效果的
model 创建链接池使用的引用变量 自己测试没问题 想听一下权威的建议
public function __construct(&$transmit, $params)
{
$this->transmit = &$transmit;
$this->params = $params;
if (isset($this->transmit['dbs'][$this->database])
&& $this->transmit['dbs'][$this->database] instanceof MysqlObject) {
$this->db = $this->transmit['dbs'][$this->database];
} else {
$db = PoolManager::getInstance()->getPool($this->getMysqlPool())->getObj(Config::getInstance()->getConf('mysql.' . $this->database . '.POOL_TIME_OUT'));
$this->db = $this->transmit['dbs'][$this->database] = $db;
}
if (!($this->db instanceof MysqlObject)) {
throw new \Exception($this->database . 'mysql pool is empty');
}
}
这种方式调用的mysql池 自己测试没有问题
是在controller 和 model 中使用getModel调用 model
/**
- @var $serviceModel ServiceModel
*/
$serviceModel = $this->getModel(ServiceModel::class);
protected function getModel($model)
{
if (!class_exists($model)) {
$this->error('model 类' . $model . '
不存在!');
}
$obj = new $model($this->transmit, $this->params);
return $obj;
}
释放连接池也是在 如 controller gc()中完成
但是之前有人在群里说这种方式 怎么死的也不会知道 就是心理有点怪怪的
不知道这种方式会不会真有问题
只是想用这种方式实现 没有mysql代理情况下的分库 和 跨model的事务嵌套
auto add back quote
使用计数器开启嵌套事务出现问题在初始化的时候没有 导致回滚出错+计数器
改造后:
public function startTransactionWithCount($resetLevel = false)
{
// 强制结束上次事务并重开
if ($resetLevel) {
$this->transactionLevel = 0;
$this->rollback();
$this->commit();
}
++$this->transactionLevel;
if ($this->transactionLevel == 1) {
$this->startTransaction();
}
}
public function commitWithCount()
{
if ($this->transactionLevel == 1) {
$this->commit();
}
$this->transactionLevel--;
}
public function rollbackWithCount($commit = true)
{
if ($this->transactionLevel == 1) {
$this->transactionLevel = 0;
$this->rollback($commit);
} else {
$this->transactionLevel--;
}
}
如何获取插入记录的自增id?
更新到最新的easyswoole 3.2.2-dev,数据库频繁出现连接问题
connect to [email protected] at port 3306 fail: 111 Connection refused
新旧文件对比
vendor\easyswoole\mysqli\src\Mysqli.php
private $currentReconnectTimes = 0;
增加这个后就频繁出现问题
之前版本3.2.19不会
不支持where括号嵌套语句,只能手写,但是特殊情况相当麻烦,比如in多值条件特别麻烦
贡上一个简单的函数,功能非常羞涩
public function buildWhere($fields)
{
if (count($fields) > 1 && isset($fields[0]) && is_string($fields[0])) {
$tmpFill = [null, null, '='];
list($field, $params, $operator) = $fields + $tmpFill;
switch (strtolower($operator)) {
case 'not in':
case 'in':
$inSql = '';
foreach ($params as $param) {
if (is_string($param)) {
$inSql .= ", '{$param}' ";
} else {
$inSql .= ", {$param} ";
}
}
$newSql = "" . $field . "
" . strtoupper($operator) . "(" . ltrim($inSql, ',') . ") ";
break;
case 'not between':
case 'between':
$beginStr = is_string($params[0]) ? "'{$params[0]}'" : $params[0];
$endStr = is_string($params[1]) ? "'{$params[1]}'" : $params[1];
$newSql = "{$field}
" . strtoupper($operator) . " {$beginStr} AND {$endStr} ";
break;
default:
if (is_string($params)) {
$newSql = "" . $field . "
" . strtoupper($operator) . " '" . $params . "' ";
} elseif ($params === null) {
$newSql = "" . $field . "
" . strtoupper($operator) . " NULL";
} else {
$newSql = "" . $field . "
" . strtoupper($operator) . " " . $params . " ";
}
}
return $newSql;
} else {
$whereArray = [];
$cond = $fields[count($fields) - 1];
if (is_string($cond) && in_array(strtoupper($cond), ['OR', 'AND'])) {
$cond = strtoupper($cond);
unset($fields[count($fields) - 1]);
} else {
$cond = ' AND ';
}
foreach ($fields as $value) {
$whereArray[] = $this->buildWhere($value);
}
return " ( " . implode($cond, $whereArray) . " ) ";
}
}
使用方法:
$db = Mysql::defer('mysql');
$where = $db->buildWhere([
["ip", "%127.0.0.1%", 'like'],
[
['id', '1', '>'],
[
['id', ['5', 10], 'not in'],
['id', '1'],
'or'
],
["username", "abc"],
'or'
],
'and'
]);
$db->where($where)->get('user');
// "SELECT * FROM user WHERE (
//ip
LIKE '%127.0.0.1%' AND (
//id
> '1' OR (
//id
NOT IN( '5' , 10 ) OR
//id
= '1' )
// ORusername
= 'abc'
// )
// ) "
implode参数顺序问题, $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';php7.4要发布了
抛出异常的时候是bind之前的语句,感觉抛出lastQuery更方便开发者定位错误
Mysqli.php line:1508=>$query=$this->query;
$this->query:SELECT * FROM ims_core_cache WHERE key = ? AND id >= ? AND id1 = ? LIMIT 1
$this->lastQuery:SELECT * FROM ims_core_cache WHERE key = 'account:ticket' AND id >= 3 AND id1 = 1 LIMIT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.