public function prepare($sql, $link = null, $resetParams = true)
{
$resetParams && $this->reset();
is_null($link) && ($link = $this->wlink);
$sqlParams = [];
foreach ($this->bindParams as $key => $val) {
$sqlParams[] = ':param' . $key;
}
$this->currentSql = $sql;
$sql = vsprintf($sql, $sqlParams);
$stmt = $link->prepare($sql);
//pdo默认情况prepare出错不抛出异常只返回Pdo::errorInfo
if ($stmt === false) {
$error = $link->errorInfo();
throw new \InvalidArgumentException('Pdo Prepare Sql error! ,【Sql : ' . $this->buildDebugSql() . '】,【Code:' . $link->errorCode() . '】, 【ErrorInfo!:' . $error[2] . '】 <br />');
} else {
foreach ($this->bindParams as $key => $val) {
is_int($val) ? $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_INT) : $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_STR);
}
return $stmt;
}
return false;
}