2
public function insert_new_listing($listing_assoc_array) {
global $public_connection;
$date = (string) date("Y-m-d");
$hit_count = 0;
if ($stmt = new mysqli_stmt($public_connection, 'INSERT INTO laptops (brand_name, title, description, price, discount, last_change_date, hit_count) VALUES (?,?,?,?,?,?,?)')) {
/* bind parameters for markers */
$stmt->bind_param(
"sssdisi",
$listing_assoc_array['brand_name'],
$listing_assoc_array['title'],
$listing_assoc_array['description'],
$listing_assoc_array['price'],
$listing_assoc_array['discount'],
$date,
$hit_count
);
/* execute query */
$stmt->execute();
我收到錯誤:變量數與準備語句中的參數數不匹配。變量數與準備語句中的參數數不匹配
我在準備語句和bind_param中有正確的數字(7),所以我不知道爲什麼會發生這種情況。
我的印象是,第一個參數是指定要注入的變量的類型..? [link](http://www.php.net/manual/en/mysqli-stmt.bind-param.php) – Angelo
視爲['mysqli_stmt']](http://php.net/manual/class.mysqli -stmt.php)沒有文檔化的公共構造函數,我會堅持使用'$ public_connection-> prepare()'而不是'new mysqli_stmt()'。我知道這可能是現在的工作,但這些是可以改變的一些事情,恕不另行通知 – Phil