2014-10-30 192 views
-1

不確定這裏有什麼問題,但我無法使用下面的插入操作。PDO插入語句無法插入db

$dbhost = "localhost"; 
$dbname = "database"; 
$dbusername = "root"; 
$dbpassword = "root"; 

$link = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbusername,$dbpassword); 

$statement = $link->prepare("INSERT INTO bloke(question, dte) 
    VALUES(:q, :d,)"); 
$statement->execute(array(
    "q" => "Bob", 
    "d" => "19/12/2014" 
)); 

回答

2

在執行方法你必須通過綁定PARAM在查詢(包括結腸癌太)

$statement->execute(array(
     ":q" => "Bob", 
     ":d" => "19/12/2014" 
    )); 

看到正式文件例如2 click me!!

+0

不工作仍然.. – X10nD 2014-10-30 12:09:43

+0

' print_r($ statement-> errorInfo());'顯示此語句的結果請在'$ statement-> execute()'方法下執行 – gvgvgvijayan 2014-10-30 12:13:19

+0

Array([0] => 01000 [1] => 1265 [2] =>第1行的列'dte'被截斷的數據) – X10nD 2014-10-30 12:14:33