💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Coroutine\MySQL->prepare 向`MySQL`服务器发送`SQL`预处理请求。`prepare`必须与`execute`配合使用。预处理请求成功后,调用`execute`方法向`MySQL`服务器发送数据参数。 ```php function Coroutine\MySQL->prepare(string $sql, float $timeout) : bool ``` > 需要`2.0.11`或更高版本 参数 ---- * `$sql` 预处理语句,使用`?`作为参数占位符 * `$timeout` 超时时间 返回值 ---- * 失败返回`false`,可检查`$db->error`和`$db->errno`判断错误原因 * 成功返回`Coroutine\MySQL\Statement`对象,可调用对象的`execute`方法发送参数 示例 ---- ```php 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); } }); ```