【问题标题】:PHP PDO insert not returning expect from operationPHP PDO插入未从操作返回期望
【发布时间】:2017-05-30 05:29:43
【问题描述】:
try {
                    print_r($con->_con);
                    $save_transaction1 = $con->_con->prepare("INSERT INTO hpay "
                            . "(amt,entryby,orno,chrgcode) VALUES "
                            . "(:amt,:entryby,:orno,:chrgcode)");
                    $save_transaction1->bindValue(":amt", $tenderedamount, PDO::PARAM_STR);
                    $save_transaction1->bindValue(":entryby", $_SESSION['account_id'], PDO::PARAM_STR);
                    $save_transaction1->bindValue(":orno", $ornumber, PDO::PARAM_STR);
                    $save_transaction1->bindValue(":chrgcode", $chargecode, PDO::PARAM_STR);
                    if ($save_transaction1->execute()) {
                        echo "asd";
                    } else {
                        print_r($con->_con->errorInfo());
                    }
                } catch (PDOException $e) {
                    echo $e;
                }

我有这个在我的数据库中插入数据。但我得到的不是我期望的它没有插入数据库,我得到的 print_r() 是

更新错误

PDO 对象 ( ) 数组 ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )

【问题讨论】:

  • 什么是 $dbh 和 $con?
  • @Exprator 抱歉,我没有从我在 SO 中找到的示例中更改它并发布了错误
  • @Exprator 错误是什么意思?我不明白错误
  • 这个错误意味着你在 bindvalue 中传递的变量是空白的,尝试打印并检查其中是否有值

标签: php database pdo insert


【解决方案1】:

错误

Array ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )

表示不存在空列并插入空表示您不能将空插入到非空列中

解决方案:

将非空列更改为空列

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多