php连接mycat的驱动类用的是liu21st的DbMysql.class.php
主要代码如下:
/**
* 连接数据库方法
* @access public
* @throws ThinkExecption
*/
public function connect($config='',$linkNum=0,$force=false) {
if ( !isset($this->linkID[$linkNum]) ) {
if(empty($config)) $config = $this->config;
// 处理不带端口号的socket连接情况
$host = $config['hostname'].($config['hostport']?":{$config['hostport']}":'');
// 是否长连接
$pconnect = !empty($config['params']['persist'])? $config['params']['persist']:$this->pconnect;
if($pconnect) {
$this->linkID[$linkNum] = mysql_pconnect( $host, $config['username'], $config['password'],131072);
}else{
$this->linkID[$linkNum] = mysql_connect( $host, $config['username'], $config['password'],true,131072);
}
if ( !$this->linkID[$linkNum] || (!empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) ) {
throw_exception(mysql_error());
}
$dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
//使用UTF8存取数据库
mysql_query("SET NAMES '".C('DB_CHARSET')."'", $this->linkID[$linkNum]);
//设置 sql_model
if($dbVersion >'5.0.1'){
// mysql_query("SET sql_mode=''",$this->linkID[$linkNum]);
}
// 标记连接成功
$this->connected = true;
// 注销数据库连接配置信息
if(1 != C('DB_DEPLOY_TYPE')) unset($this->config);
}
return $this->linkID[$linkNum];
}
每次连接的时候,mycat日志都会出现如下:
2020-06-15 17:05:31.867 INFO [$_NIOREACTOR-3-RW] (io.mycat.net.handler.FrontendAuthenticator.success(FrontendAuthenticator.java:226)) - ServerConnection [id=17, schema=null, host=10.10.10.136, user=admin,txIsolation=3, autocommit=true, schema=null, executeSql=null]'admin' login success
2020-06-15 17:05:31.867 ERROR [$_NIOREACTOR-3-RW] (io.mycat.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:124)) - Unknown command:
020-06-15 17:05:31.868 ERROR [$_NIOREACTOR-3-RW] (io.mycat.net.FrontendConnection.writeErrMessage(FrontendConnection.java:210)) - ServerConnection [id=17, schema=test, host=10.10.10.136, user=admin,txIsolation=3, autocommit=true, schema=test, executeSql=null]Unknown commandjava.lang.Thread .getStackTrace1559
io.mycat.net.FrontendConnection .getStack224
io.mycat.net.FrontendConnection .writeErrMessage210
io.mycat.net.handler.FrontendCommandHandler .handle125
io.mycat.net.FrontendConnection .rawHandle570
io.mycat.net.FrontendConnection .handle552
io.mycat.net.AbstractConnection .onReadData327
io.mycat.net.NIOSocketWR .asynRead216
io.mycat.net.AbstractConnection .asynRead279
io.mycat.net.NIOReactor$RW .run113
java.lang.Thread .run748
write errorMsg:{} error
2020-06-15 17:05:31.884 INFO [$_NIOREACTOR-3-RW] (io.mycat.net.AbstractConnection.close(AbstractConnection.java:520)) - close connection,reason:quit cmd ,ServerConnection [id=17, schema=test, host=10.10.10.136, user=admin,txIsolation=3, autocommit=true, schema=test, executeSql=null]
求教一下为什么会有个执行sql为null的语句,上图的ERROR