phpmysqlpdomysql-error-1146

PDO give Mysql Error 1146


    $deleteID = $_POST['oz'];
    if(!$deleteID){
        echo '2';
        die;    
    } else {
        //It should be working.
    }
    $checkVar = $pdo->prepare("SELECT * FROM `user_posts` WHERE `id`=:delete");
    $checkVar->bindValue(':delete',$deleteID,PDO::PARAM_STR);
    if($checkVar->execute() == false){
        echo '2';
        die;
    }

I'm really pissed off. $deleteID is supplied, nothing is being binded. Why not, please someone help.


Solution

    1. make PDO to throw exception on error,
      $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
      after connect.
    2. Make sure you can see errors occurred, either in logs or on the screen.
    3. Run the very code you posted here, not some other code. As in the other code there can be other errors, irrelevant to your binding problem.

    For the Table doesn't exist problem you have to check for mistakes like typos, letter case, wrong server connected, wrong PHP file edited etc. Say, you are running your PHPMyAdmin against localhost while actual script against remote host or something of the kind.