Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
INSERT INTO-子查询返回超过1行(PHP/MySQL)_Php_Mysql_Sql_Sql Insert - Fatal编程技术网

INSERT INTO-子查询返回超过1行(PHP/MySQL)

INSERT INTO-子查询返回超过1行(PHP/MySQL),php,mysql,sql,sql-insert,Php,Mysql,Sql,Sql Insert,我正在尝试用PHP和MySQL开发一个网站。以下是我尝试过的PHP代码: $sql = sprintf("INSERT INTO request_boms SET request_list_id = %d, project_version_id = %d, amount = %d,

我正在尝试用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);
My
$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-to
查询中,我没有给出任何
SELECT
语句。怎么可能呢

编辑(由于评论)

这是我的
Execute()

记录集

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\u components
的表。它有两个主键:
id
request\u list\u id
。从表中删除
request\u list\u id
键后,问题得到解决。这似乎会在表之间产生冲突。如果出现此问题,应检查数据库。

已解决!
在我的数据库中还有一个名为
request\u components
的表。它有两个主键:
id
request\u list\u id
。从表中删除
request\u list\u id
键后,问题得到解决。这似乎会在表之间产生冲突。如果您有这个问题,您应该检查您的数据库。

我的所有函数都带有错误处理。只有此查询提供了一个错误:/INSERT根本不返回行。如果您的代码等待返回的行,则您使用了不正确的执行方法或选项。请向我们显示
Execute()
。我们需要看看导致这种情况的代码。我添加了它@Magnuseriksson请将您的答案/解决方案添加为答案;不要把它编辑成问题。我所有的函数都有错误处理。只有此查询提供了一个错误:/INSERT根本不返回行。如果您的代码等待返回的行,则您使用了不正确的执行方法或选项。请向我们显示
Execute()
。我们需要看看导致这种情况的代码。我添加了它@Magnuseriksson请将您的答案/解决方案添加为答案;不要把它编辑成问题。
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;
    }
}