\swoole_mysql

Class Mysql

Summary

Methods
Properties
Constants
__construct()
on()
connect()
escape()
query()
begin()
commit()
rollback()
close()
$connect_errno
$connect_error
$errno
$error
$insert_id
$affected_rows
$connect_errno
$connect_error
$errno
$error
$insert_id
$affected_rows
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$connect_errno

$connect_errno : string

Type

string — the connect error number

$connect_error

$connect_error : string

Type

string — the connect error information

$errno

$errno : string

Type

string — the error number when query fail

$error

$error : string

Type

string — the error information when query fail

$insert_id

$insert_id : integer

Type

integer — the last insert id when query execute success

$affected_rows

$affected_rows : integer

Type

integer — the affected rows when query execute success

$connect_errno

$connect_errno : 

Type

$connect_error

$connect_error : 

Type

$errno

$errno : 

Type

$error

$error : 

Type

$insert_id

$insert_id : 

Type

$affected_rows

$affected_rows : 

Type

Methods

__construct()

__construct() 

on()

on(string  $eventName, callable  $callback) 

set the event callback, current just support close function callback(\Swoole\Mysql $db){}

Parameters

string $eventName
callable $callback

connect()

connect(array  $config, callable  $callback) 

$config = array( 'host' => '192.168.56.102', // the host for mysql server ,support ipv4,ipv6 or unix sock.

'user' => 'test', // mysql user name 'password' => 'test', // password for mysql 'database' => 'test', // the database 'charset' => 'utf8', // choice, if not given, the server charset used ); function callback(\Swoole\Mysql $db, bool $result) { }

Parameters

array $config
callable $callback

Throws

\Swoole\Mysql\Exception

$e

escape()

escape(string  $str) : string

use mysqlnd to escape the string use --enable-mysqlnd when compile

Parameters

string $str

Returns

string

query()

query(string  $sql, callable  $callback) 

function callback(\Swoole\Mysql $link, mixed $result) {} when execute fail, the result return false, you can use $link->error and $link->errno to get the error information.

success: if query result sql, the result is the query result otherwise the result is true, you can use $link->insert_id, $link->affected_rows

Parameters

string $sql
callable $callback

begin()

begin(callable  $callback) 

start a new transaction one link only one transaction, if already exist, then exception function callback(\Swoole\Mysql $link, mixed $result) {}

Parameters

callable $callback

Throws

\Swoole\Mysql\Exception

$e

commit()

commit(callable  $callback) 

commit transaction if not exist, then exception function callback(\Swoole\Mysql $link, mixed $result) {}

Parameters

callable $callback

Throws

\Swoole\Mysql\Exception

$e

rollback()

rollback(callable  $callback) 

rollback transaction if not exist, then exception function callback(\Swoole\Mysql $link, mixed $result) {}

Parameters

callable $callback

Throws

\Swoole\Mysql\Exception

$e

close()

close() 

close the connection