PDO:无效参数号:参数未定义
PDO : Invalid parameter number: parameter was not defined
作为 pdo class 我使用 https://github.com/indieteq/PHP-MySQL-PDO-Database-Class 这是我的插入代码。插入操作时出现错误(select 函数没有问题)我不知道如何解决它,感谢您的帮助。
$insert = $db->query("INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)", array(
':user_id' => $this->user_id,
':post_name' => $this->post_name(),
':color' => $params['color'],
':start_date' => $params['start_date'],
':expire_date' => $expDate,
':content' => $params['content'],
':title' => $params['title'],
':status' => $params['status'],
':rate' => $params['rate'],
':category' => $params['category'],
':created' => $cDate,
':changed' => $chang,
':target'=> 1
));
Unhandled Exception.
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
You can find the error back in the log.
Time : 18:19:05
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Raw SQL : INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)
这是我的 vardump 表单 $_POST 表单传递
array(9) {
["color"]=>
string(6) "c22bc2"
["start_date"]=>
string(19) "2014-12-31 18:23:31"
["expire_date"]=>
string(19) "2015-01-08 18:23:33"
["content"]=>
string(70) "
sDOROS)()GJ)*(EH)* VN#MT#:????><?<>?>??)T#\\'\
"
["title"]=>
string(23) "Tesssssssssssssssssssss"
["status"]=>
string(7) "publish"
["target"]=>
string(4) "stud"
["rate"]=>
string(1) "5"
["category"]=>
string(5) "w_zal"
}
如果需要
$cDate = date("Y-m-d H:i:s");
$chang = 0;
public function post_name()
{
global $db;
$n = $db->row("SELECT max(id) as id FROM post");
$post_name = $this->user . "-" . $n['id'] . "-" . session_id();
return $post_name;
}
private function user_id()
{
global $db;
$userid = $db->row("SELECT * FROM users WHERE user_name = :name", array(
"name" => $_SESSION['user_name']
));
$this->user_id = $userid['user_id'];
return $this->user_id;
}
整个 class : http://pastebin.com/ehPazdMm
作为 pdo class 我使用 https://github.com/indieteq/PHP-MySQL-PDO-Database-Class 这是我的插入代码。插入操作时出现错误(select 函数没有问题)我不知道如何解决它,感谢您的帮助。
$insert = $db->query("INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)", array(
':user_id' => $this->user_id,
':post_name' => $this->post_name(),
':color' => $params['color'],
':start_date' => $params['start_date'],
':expire_date' => $expDate,
':content' => $params['content'],
':title' => $params['title'],
':status' => $params['status'],
':rate' => $params['rate'],
':category' => $params['category'],
':created' => $cDate,
':changed' => $chang,
':target'=> 1
));
Unhandled Exception.
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
You can find the error back in the log.
Time : 18:19:05
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Raw SQL : INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)
这是我的 vardump 表单 $_POST 表单传递
array(9) {
["color"]=>
string(6) "c22bc2"
["start_date"]=>
string(19) "2014-12-31 18:23:31"
["expire_date"]=>
string(19) "2015-01-08 18:23:33"
["content"]=>
string(70) "
sDOROS)()GJ)*(EH)* VN#MT#:????><?<>?>??)T#\\'\
"
["title"]=>
string(23) "Tesssssssssssssssssssss"
["status"]=>
string(7) "publish"
["target"]=>
string(4) "stud"
["rate"]=>
string(1) "5"
["category"]=>
string(5) "w_zal"
}
如果需要
$cDate = date("Y-m-d H:i:s");
$chang = 0;
public function post_name()
{
global $db;
$n = $db->row("SELECT max(id) as id FROM post");
$post_name = $this->user . "-" . $n['id'] . "-" . session_id();
return $post_name;
}
private function user_id()
{
global $db;
$userid = $db->row("SELECT * FROM users WHERE user_name = :name", array(
"name" => $_SESSION['user_name']
));
$this->user_id = $userid['user_id'];
return $this->user_id;
}
整个 class : http://pastebin.com/ehPazdMm