だから私は本で見つけたこの機能を使用していますが、うまくいかないようです。
/*
Update records in the database
@param String the table
@param Array of changes field => value
@param String the condition
@return Bool
*/
public function updateRecords($table, $changes, $condition){
$update = " UPDATE " . $table . " SET ";
foreach($changes as $field => $value){
$update .= "`" . $field . "`='{$value}',";
}
//remove our trailing ,
$update = substr($update, 0, -1);
if($condition != ""){
$update .= " WHERE " . $condition;
}
$this->executeQuery($update);
return true;
}
次のようにオブジェクトをインスタンス化しました。
$a = new Mysqldb($z);
$g = $a->newConnection("localhost", "root", "secrete", "mydatabase");
指定された方法を次のように使用しました。
$a->updateRecords("members", array("id" => 10, "username" => "Paco"), " WHERE id= 10");
しかし、構文にエラーがあると言って、うまくいきません。
Fatal error: Error executing query: UPDATE members SET `id`='10',`username`='Paco' WHERE WHERE id= 10 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=10' at line 1 in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\MVC\registry\mysqldb.class.php on line 86
そのため、バッククォートを使用してコマンド ラインで同じクエリを直接実行したところ、成功しました。助言がありますか?