对不起,我的英语我是法国人:d,PDO参数错误
好吧,我使用PDO我的Connexion公司与MySQL,但我有一个错误与PDO准备语句。
我尝试,包括我的表名进入准备请求,但我有一个错误:
错误:SQLSTATE [42000]:语法错误或访问冲突1064您的SQL语法错误;检查的行对应于你的MySQL服务器版本正确的语法使用近'NbClient“LIMIT 2)SR” 1个 错误代码手册:42000
我的代码:
<html>
<head>
</head>
<body>
<?php
const HOST='localhost';
const DBNAME='GameWave';
const USER='';
const PASSWORD='';
const TABLE='NbClient';
echo GetNbClientByHour(2);
function GetNbClientByHour($nb_heure)
{
$hookConstTable = TABLE;
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$connexion = new PDO('mysql:host='.HOST.';dbname='.DBNAME, USER, PASSWORD, $pdo_options);
$prepare=$connexion->prepare('select SUM(record) from (select v_tot as record from :tab LIMIT :nb_heure) as sr;');
$prepare->bindParam(':tab', $hookConstTable, PDO::PARAM_STR);
$prepare->bindParam(':nb_heure', $nb_heure, PDO::PARAM_INT);
$prepare->execute();
$resultat = $prepare->fetch();
$prepare->closeCursor();
return $resultat[0];
}
catch(Exception $e)
{
echo 'Error : '.$e->getMessage().'<br />';
echo 'Error Code : '.$e->getCode();
}
}
?>
</body>
</html>
但如果我尝试写请求中的表名,它的工作...
$prepare=$connexion->prepare('select SUM(record) from (select v_tot as record from NbClient LIMIT :nb_heure) as sr;');
$prepare->bindParam(':nb_heure', $nb_heure, PDO::PARAM_INT);
请问你能帮我吗?
如果没有别的,为什么不只是'选择sum(v_tot)作为记录从nbclient'?子选择 –