21 declare(strict_types=1);
66 $this->credentials =
serialize($credentials);
69 protected function createConn(&$mysqli) : ?string{
71 $cred =
unserialize($this->credentials, [
"allowed_classes" => [MysqlCredentials::class]]);
73 $mysqli = $cred->newMysqli();
81 assert($mysqli instanceof mysqli);
83 $result = $mysqli->query($query);
84 if($result ===
false){
103 $ret = $this->toSelectResult($result);
108 $stmt = $mysqli->prepare($query);
124 $stmt->bind_param($types, ...$params);
125 if(!$stmt->execute()){
145 $set = $stmt->get_result();
146 $ret = $this->toSelectResult($set);
159 while(($field = $result->fetch_field()) !==
false){
160 if($field->length === 1){
163 $columnFunc[$field->name] =
function($tiny){
168 $columnFunc[$field->name] =
function($bit){
169 return $bit ===
"\1";
175 $columnFunc[$field->name] =
function($longLong) use ($field){
177 if(
bccomp($longLong,
"9223372036854775807") === 1){
178 $longLong =
bcsub($longLong,
"18446744073709551616");
180 return (
int) $longLong;
183 return (
int) $longLong;
187 $columnFunc[$field->name] =
function($stamp){
200 $columnFunc[$field->name] =
"floatval";
203 $columnFunc[$field->name] =
"intval";
208 $columns[$field->name] =
new MysqlColumnInfo($field->name, $type, $field->flags, $field->type);
212 while(($row = $result->fetch_assoc()) !== null){
213 foreach($row as $col => &$cell){
214 if($cell !== null && isset($columnFunc[$col])){
215 $cell = $columnFunc[$col]($cell);
222 return new SqlSelectResult($columns, $rows);
225 protected function close(&$mysqli) : void{
226 assert($mysqli instanceof mysqli);
231 return __NAMESPACE__ .
" connector #$this->slaveNumber";
executeQuery($mysqli, int $mode, string $query, array $params)
static createFactory(MysqlCredentials $credentials)
__construct(MysqlCredentials $credentials, QuerySendQueue $bufferSend=null, QueryRecvQueue $bufferRecv=null)