Juste一个简单的pdo请求不起作用。我不明白。真的没有。
$d = strtotime("today");
$start_week = strtotime("last sunday midnight",$d);
$start = date("Y-m-d",$start_week);
$s1 = $db->prepare("SELECT leads where humeur != 'Doublon' and date_import between :start and :end");
$s1->bindParam(':start', $start);
$s1->bindParam(':end', $today);
try{
$s1->execute();
}
catch (Exception $e) {
echo 'Exception reçue : ', $e->getMessage(), "\n";
}
知道了。
异常reçue:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以便在第1行的'2015-03-29'和'2015-04-01'之间的'where humeur!='Doublon'和date_import附近使用正确的语法
如果有人看到我不知道的事情,我将不胜感激。
答案 0 :(得分:1)
您的查询不正确,缺少您要选择的表格。
您需要更新您的查询:
$d = strtotime("today");
$start_week = strtotime("last sunday midnight",$d);
$start = date("Y-m-d",$start_week);
// Replace tableName with the actual name of the table
$s1 = $db->prepare("SELECT leads FROM tableName where humeur != 'Doublon' and date_import between :start and :end");
$s1->bindParam(':start', $start);
$s1->bindParam(':end', $today);
try{
$s1->execute();
}
catch (Exception $e) {
echo 'Exception reçue : ', $e->getMessage(), "\n";
}
答案 1 :(得分:-1)
你的联系:
$hostname_conn = "xxxx";
$database_conn = "xxx";
$username_conn = "xxx";
$password_conn = "xxx";
PDO
try{
$bdd=new PDO("mysql:host=$hostname_conn; dbname=$database_conn","$username_conn","$password_conn");
$bdd->EXEC('SET CHARACTER SET utf8');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}catch(Exception $e){
die('Error: '.$e->getMessage());
}
现在你的要求:
$s1 = $bdd->prepare("SELECT leads from yourtable where humeur != 'Doublon' and date_import between :start and :end");
$s1->bindParam(':start', $start);
$s1->bindParam(':end', $today);
$s1->execute();
while ($row = $s1->fetch(PDO::FETCH_ASSOC))
{
...;
}