致命错误:未捕获PDOException

时间:2017-01-27 08:40:28

标签: php mysql pdo

我在尝试删除项目时遇到以下错误。

  

致命错误:未捕获PDOException:SQLSTATE [42S02]:基表或   找不到视图:1146表'databaseName.tableName'不存在于   /storage/h1/735/500735/public_html/delete.php:21堆栈跟踪:#0   /storage/h1/735/500735/public_html/delete.php(21):   抛出PDOStatement-> execute()#1 {main}   第21行/storage/h1/735/500735/public_html/delete.php

注意:tableName此处为tblcart

delete.php

<?php
    session_start();
    require("dbconfig.php");
    if (isset($_GET['delete_id'])) {
        $stmt_select = $DB_con->prepare('SELECT * FROM tblcart WHERE productID =:id');
        $stmt_select->execute(array(':id'=>$_GET['delete_id']));
        $result=$stmt_select->fetch(PDO::FETCH_ASSOC);

        $stmt_delete = $DB_con->prepare('DELETE FROM tblCart WHERE productID =:id AND userID =:userID');
        $stmt_delete->bindParam(':id',$_GET['delete_id']);
        $stmt_delete->bindParam(':userID',$_SESSION['userid']);
        $stmt_delete->execute();

        header("Location: cart.php");
    }
?>

请参阅错误说明,第$stmt_delete->execute();行发生错误。如果我通过我的本地PC localhost运行代码它运行良好,但在web托管服务器上运行时,我收到此错误。

编辑:

以下是dbconfig.php

dbconfig.php

<?php

    $DB_HOST = 'localhost';
    $DB_USER = 'root';
    $DB_PASS = 'password';
    $DB_NAME = 'databaseName';

    try{
        $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USER,$DB_PASS);
        $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    catch(PDOException $e){
        echo $e->getMessage();
    }
?>

1 个答案:

答案 0 :(得分:2)

Linux 服务器上的

new SimpleDateFormat("MMMM dd yyyy hh:mm aa"),区分大小写为&#34; on &#34;。

区分大小写为&#34; 关闭&#34;

这就是为什么它适用于您的计算机(Windows),而不适用于Web托管服务器(linux)

从以下位置更改删除语句:

Database and table names

致:

Database and table names

差异为$stmt_delete = $DB_con->prepare('DELETE FROM tblCart WHERE productID =:id AND userID =:userID'); $stmt_delete = $DB_con->prepare('DELETE FROM tblcart WHERE productID =:id AND userID =:userID');

参考here