i've used following code in order fill database using pdo:
$stmt = $pdo->prepare(" insert :season values ( :tag,:rank, //and on ); "); for($l = 0; $l < count($data); $l++) { $stmt->execute([ 'season' => $tables[$i], 'tag' => $data[$l]["tag"], 'rank' => $data[$l]["rank"], // , on ]); }
but response is:
syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mariadb server version right syntax use near '? values ( ?,?,?,?,?,?,?,?,? )' @ line 1' in e:\xampp\htdocs\coc_api\legenden\sql_test\api_sql.php
does know error is?
must put every entry in quotes?
you bind values in wrong way. have use name :
in prepared query. can see examples in documentation of execute
method http://php.net/manual/en/pdostatement.execute.php
replace part of code
for($l = 0; $l < count($data); $l++) { $stmt->execute([ 'season' => $tables[$i], 'tag' => $data[$l]["tag"], 'rank' => $data[$l]["rank"], // , on ]); }
with this
for($l = 0; $l < count($data); $l++) { $stmt->execute([ ':season' => $tables[$i], ':tag' => $data[$l]["tag"], ':rank' => $data[$l]["rank"], // , on ]); }
you can use bindvalue
method in way
for($l = 0; $l < count($data); $l++) { $stmt->bindvalue(':season', $tables[$i]); $stmt->bindvalue(':tag', $data[$l]["tag"]); $stmt->bindvalue(':rank', $data[$l]["rank"]); //and on } $stmt->execute();
Comments
Post a Comment