簡體   English   中英

INSERT INTO - 子查詢返回超過 1 行 (PHP/MySQL)

[英]INSERT INTO - Subquery returns more than 1 row (PHP/MySQL)

我正在嘗試使用 PHP 和 MySQL 開發一個網站。 這是我試過的 PHP 代碼:

$sql = sprintf("INSERT INTO request_boms SET
                                request_list_id = %d,
                                project_version_id = %d,
                                amount = %d,
                                user = '%s',
                                timestamp = %d",
                                $requestNo, $bomID, $amount, $_SESSION["admin_user_name"], time());
$this->db_inventory->Execute($sql);

我的$this->db_inventory變量與 DB API 連接。 沒有問題。 但是當我在這里執行代碼時,會返回這個:

Subquery returns more than 1 row
INSERT INTO request_boms SET request_list_id = 14, project_version_id = 429, amount = 1, user = 'admin', timestamp = 1607510083

我在這里搜索了這個問題(stackoverflow),但在所有問題中,他們的查詢中都有SELECT語句。 我沒有在我的INSERT INTO查詢中給出任何SELECT語句。 怎么可能?

編輯(由於評論)

這是我的Execute()

public function Execute($sql) {
    $rs = new RecordSet($sql, $this->db_type, $this->conn);
    return $rs;
}

RecordSet

class RecordSet {
    public $rs;
    public $db_type;
    public $conn;

    public function RecordSet($sql, $db_type, $conn) {
        $this->db_type = $db_type;
        $this->conn = $conn;
        if ($this->db_type == 'sybase') {
            $rsx =@sybase_query($this->sql_escape($sql)); 
            if (!$rsx) {
                $this->queryError(sybase_get_last_message(),$sql);
            }
        } elseif ($this->db_type == 'mssql') {
            $rsx =@mssql_query($this->sql_escape($sql)); 
            if (!$rsx) {
                $this->queryError(mssql_get_last_message(),$sql);
            }
        } elseif ($this->db_type == 'odbc') {
            $rsx =@odbc_exec($this->conn, $this->sql_escape($sql)); 
            if (!$rsx) {
                $this->queryError(odbc_errormsg(),$sql);
            }
        } else {
            $rsx = mysqli_query($this->conn, $this->sql_escape($sql));
            if (!$rsx) {
                $this->queryError(@mysqli_error($this->conn),$sql);
            }
        }
        $this->rs = $rsx;
    }
}

解決了!

在我的數據庫中,我還有一個名為request_components的表。 它有 2 個主鍵: idrequest_list_id 從表中刪除request_list_id鍵后,問題解決了。 似乎在表之間產生沖突。 如果你有這個問題,你應該檢查你的數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM