1
我查看了一些與我的問題類似的其他問題,但我沒有在此使用數組或循環PDO數據庫編寫器腳本。由於其他解決方案的困惑,我仍然發現自己陷入了這個問題。PHP腳本返回:SQLSTATE [HY093]:無效的參數編號:參數未定義
我的腳本是這樣寫的:
<?php
class DatabaseWriter
{
public function writeUserToDatabase($email , $name , $age , $gender , $country , $category)
{
$host = '***********';
$dbname = 'emailcollection';
$user = '**********';
$pass = '**********';
$jointime = '2013-01-07 11:19:08';
try {
$connection = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $user, $pass);
$connection -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $connection -> prepare("INSERT INTO emailcollection (emailaddress, name, age, gender, country, category, jointime) VALUES (:emailaddress, :name, :age, :gender, :country, :category, :jointime)");
$statement -> bindValue(':email', $email);
$statement -> bindValue(':name', $name);
$statement -> bindValue(':age', $age);
$statement -> bindValue(':gender', $gender);
$statement -> bindValue(':country', $country);
$statement -> bindValue(':category', $category);
$statement -> bindValue(':jointime', $jointime);
$statement -> execute();
$connection = NULL;
}catch (PDOException $e){
echo $e -> getMessage();
}
}
}
>
輸出:
SQLSTATE [HY093]:無效參數號:未定義的參數
您可能想知道什麼是$ jointime。這是表中的最後一列,並且由於我收到的內容是「無效的參數號」,我認爲我應該完全匹配列的數量(我試圖在寫入用戶時添加時間戳,以某種方式在PHP或SQL中)。
感謝您提前回饋。
歡迎來到Stack Overflow。不幸的是,您的問題太過本地化,無法在本網站上詢問。請學習通過您自己的努力找到您的代碼的拼寫錯誤,尤其是在您有錯誤消息的幫助下。請仔細檢查您的名字是否全部正確並匹配。這並不難。那麼請刪除你的問題。隨時歡迎您回覆真正的問題,關於某些*編程*問題 –
多麼粗魯的迴應。 –
代碼中沒有拼寫錯誤,它是一個**真正的**編程問題。 –