0

我有一个问题,如果我能得到一些帮助,我真的很乐意。我正在使用 php 应用程序与数据库进行交互。我有一个数据库,它运行良好。但是,当我备份它并将其移至另一台 PC 时,它开始起作用。它与原版相同。我有一个名为 的表Authorize,以及authorized一个默认不为空的列,但是当我尝试更新授权列时,出现以下消息(在原始系统上它仍然可以正常工作,我似乎找不到问题)。

Error: Column 'authorized' cannot be null
sql: update `authorized` set `authorized` = :authorized where `authorized_id` = :identity_id;

arr_sql_param: Array
(
[:identity_id] => 22
[:authorized] => 
)

Sent From: update_grid()
4

1 回答 1

1

阅读您的代码:

public function sql_update() {
    ...
    // make sql statement from key and values in $_POST data
    foreach($_POST as $key => $val) {
        $sql_set .= "`$key` = :$key, "; 
        $sql_param[":$key"] = $this->cast_value($val, $key);
    ...
    // posted values are saved here for pdo execute
    $sql_param = array();
    $sql_param[':identity_id'] = $identity_id;
    ...
    $sql_final = "update `$this->table` set $sql_set where `$this->identity_name` = :identity_id;";
    ...

和错误:

错误:列 'authorized' 不能为空
sql:更新authorizedauthorized= :authorized where authorized_id= :identity_id;

我意识到确实:authorized没有明确设置或包含在 SQL 语句中。

这导致了两个可能的结论:

  1. 如果在此环境中列不能为 NULL,但相同的代码在您的开发系统(您的 PC)上工作正常,那么这两个系统上的数据库方案可能不同。

    在新环境中,表中的authorizedauthorized是定义的NOT NULL,而在您的开发环境中,您没有此约束。

    比较SHOW CREATE TABLE authorized两个系统,看看这是否属实。

  2. 因为 for 的列值authorized来自$_POST数组..是否有可能由于某种原因浏览器没有发布它?但是,在您的代码中找不到原因。

于 2012-07-29T10:52:53.630 回答