我正在使用symfony2和PDO将值插入数据库。
private static function insertAction($action, $conn){
$sql = "INSERT INTO BANKACTIONS (clientName, actionDate, currency, value, actionType) VALUES (clientName, actionDate, currency, value, actionType)";
$q = $conn->prepare($sql);
$q->execute(array(':clientName'=>$action->getClientName(),
':actionDate'=>$action->getDate(),
':currency'=>$action->getCurrency(),
':value'=>$action->getValue(),
':actionType'=>$action->getActionType()));
}
}
这是数组的var_dump
actionarray(5) { [":clientName"]=> string(6) "client" [":currentDate"]=> string(10) "1358200800" [":currency"]=> string(3) "ILS" [":value"]=> string(3) "ILS" [":actionType"]=> string(7) "deposit" }
哪个是正确的......
但是当我在myphpadmin中查看表格
时我得到了
id clientName actionDate货币值actionType
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
7 0 0 0
答案 0 :(得分:2)
你可以尝试这样:
private static function insertAction($action, $conn){
$sql = "INSERT INTO BANKACTIONS
(clientName, actionDate, currency, value, actionType)
VALUES (:clientName, :actionDate, :currency, :value, :actionType)";
$q = $conn->prepare($sql);
$q->execute(array(
'clientName' => $action->getClientName(),
'currentDate' => $action->getDate(),
'currency' => $action->getCurrency(),
'value' => $action->getValue(),
'actionType' => $action->getActionType()));
}
}
SQL请求中的2分“:”并且数组中没有任何内容! :)