function query($sql) { $is_multi = true; $sign = mt_rand(); if (!is_array($sql)) { $is_multi = false; $sql = array($this->dbname => $sql); } $pack = CLPack::pack($sql, $sign); if (false === $pack) { $this->last_errno = 1256; $this->last_erro_msg = '发送的sql语句大小超过限制'; return false; } if (false === $this->conn->send($pack)) { $this->conn->close(); $this->connect(); if (false === $this->conn->send($pack)) { throw new \Exception('连接Mysql网络中断'); } } $r = $this->getPack($sign); foreach ($r as $k => $v) { if ($v[0] != 0) { $this->last_errno = $v[0]; $this->last_erro_msg = $v[1]; return false; } } $result_id = $this->result_id++; $this->result[$result_id] = $r; return $result_id; }
static function query($sql, $conn_id) { if (!isset(self::$conninfo[$conn_id])) { /*$this->last_errno = 2006; $this->last_erro_msg = 'Mysql proxy中断(无连接)';*/ self::$conninfo[$conn_id][self::CONNINFO_F_errno] = 1256; self::$conninfo[$conn_id][self::CONNINFO_F_erro_msg] = '连接不存在 $conn_id=' . $conn_id; return false; } $is_multi = true; $sign = mt_rand(); if (!is_array($sql)) { $is_multi = false; $sql = array(self::$conninfo[$conn_id][self::CONNINFO_F_dbname] => $sql); } $pack = CLPack::pack($sql, $sign); if (false === $pack) { self::$conninfo[$conn_id][self::CONNINFO_F_errno] = 1256; self::$conninfo[$conn_id][self::CONNINFO_F_erro_msg] = '发送的sql语句大小超过限制'; return false; } if (false === self::$conninfo[$conn_id][self::CONNINFO_F_conn]->send($pack)) { self::$conninfo[$conn_id][self::CONNINFO_F_errno] = 2006; self::$conninfo[$conn_id][self::CONNINFO_F_erro_msg] = 'Mysql proxy中断(发送失败)'; return false; } $r = self::getPack($sign, $conn_id); if ($r === false) { return false; } /*if (!is_array($r)) { self::$conninfo[$conn_id][self::CONNINFO_F_errno] = 1256; self::$conninfo[$conn_id][self::CONNINFO_F_erro_msg] = '返回非数组结果' . print_r($r, 1); return false; }*/ foreach ($r as $k => $v) { if ($v[0] != 0) { self::$conninfo[$conn_id][self::CONNINFO_F_errno] = $v[0]; self::$conninfo[$conn_id][self::CONNINFO_F_erro_msg] = $v[1]; return false; } else { self::$conninfo[$conn_id][self::CONNINFO_F_insert_id] = isset($v[2]) ? $v[2] : 0; self::$conninfo[$conn_id][self::CONNINFO_F_affected_rows] = isset($v[3]) ? $v[3] : 0; } } self::$result_id++; self::$result[self::$result_id] = $r; return self::$result_id; }
function reload() { $this->conn->send(CLPack::pack(CLPack::CMD_reload)); return $this->getPack(); }