0

My code is as follows:

$stmt = $this->db->prepare("INSERT INTO favorites (id, profile_id, item_id) VALUES(?, ?, ?)");
        if ($stmt)
        {
            $stmt->bind_param("sss", $maxID, $provider, $ID);
            if(!$stmt->execute())
            {
                echo ("Error" . $this->db->error);
                return $this->db->error;
            }
            else
            {
                echo("success");
            }
            $stmt->close();
        }
        else 
        {
            echo ("Error" . $this->db->error);
            return $this->db->error;
        }

Despite my best efforts, this prepared statement is not doing anything. When I type the values directly into MYSQL prompt, it works properly. However, when I run this script, it does nothing.

Notes: $maxID, $provider, $ID are all valid values to insert. It throws no errors on the script or on the server error log. I'm very confused about why it does not add a row. Is there a glaring mistake in my code?

Thanks!!

EDIT: Added up new code, same thing. Execute is passing as well.

4

2 回答 2

1

INSERT没有默默地失败——你只是没有在寻找错误。您正在检查prepare通话的返回状态,而不是通话的返回状态execute。尝试这个:

$stmt->bind_param("sss", $maxID, $provider, $ID);
$stmt->execute() or die($stmt->error);
$stmt->close();
于 2013-11-12T02:26:58.270 回答
0

PHP mysqli插入不起作用,但没有给出任何错误

原来这是我的解决方案。^ 自动提交已关闭。

于 2013-11-12T04:03:34.483 回答