向MySQL
服务器发送SQL
预处理请求。prepare
必须与execute
配合使用。预处理请求成功后,调用execute
方法向MySQL
服务器发送数据参数。
function Coroutine\MySQL->prepare(string $sql, float $timeout) : bool
需要
2.0.11
或更高版本
$sql
预处理语句,使用?
作为参数占位符$timeout
超时时间
返回值false
,可检查$db->error
和$db->errno
判断错误原因Coroutine\MySQL\Statement
对象,可调用对象的execute
方法发送参数use Swoole\Coroutine as co;
co::create(function() {
$db = new co\MySQL();
$server = array(
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'root',
'database' => 'test',
);
$ret1 = $db->connect($server);
$stmt = $db->prepare('SELECT * FROM userinfo WHERE id=?');
if ($stmt == false)
{
var_dump($db->errno, $db->error);
}
else
{
$ret2 = $stmt->execute(array(10));
var_dump($ret2);
}
});