php
  • mysql
  • pdo
  • between
  • 2015-04-01 82 views -1 likes 
    -1

    Juste一个简单的pdo请求不起作用。我不明白。真的不要。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"; 
    } 
    

    明白了。

    异常事件:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法错误;检查与您的MySQL服务器版本对应的手册,以便在第1行'2015-03-29'和'2015-04-01'之间'where humeur!='Doublon'和date_import附近使用正确的语法。

    如果有人看到我不喜欢的东西,我会很感激。

    +1

    您没有包含'FROM表格' - 'SELECT引线FROM yourTable,其中humeur' – 2015-04-01 00:13:01

    +0

    需要查询中的表格 – 2015-04-01 00:13:35

    +0

    它必须被定义,否则错误将与问题中包含的错误不同。 – 2015-04-01 00:22:16

    回答

    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

    您的Connexion:

    $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)) 
    { 
        ...; 
    } 
    
    相关问题