我正在使用全局函数来处理PHP中的MySQL需求。这是代码:
function DB_EXECUTE($query, array $array_par, $haveresult = 1){
global $db;
try {
$stmt = $db->prepare($query);
$stmt->execute($array_par);
}catch(PDOException $e)
{
echo "ERROR: " . $query . "<br>" . $e->getMessage();
}
$rowF = null;
if ($haveresult > 0){
$rowF = $stmt->fetchAll();
}
return $rowF;
}
我这样称呼函数:
$temp_query = "SELECT * FROM users ORDER BY id DESC LIMIT :one, :two";
$temp_array = array(":one" => intval($limit_from), ":two" => intval($limit_to));
$results = DB_EXECUTE($temp_query, $temp_array, 1);
//Do something with the $results
但我遇到了一个问题:
ERROR: SELECT * FROM users ORDER BY id DESC LIMIT :one, :two
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '5'' at line 1
我使用这个函数处理了很多查询,所以我不想改变我调用它的方式。相反,我想更改函数本身以支持整数类型的数据。