php mysql pdo bindparam data not insert -
when call function , shows no error, data not inserted. database connection checked , ok , connection type pdo.
public function insert(){ $table = "category"; $data = array( 'cat_id' => 5, 'cat_name_en' => 'science', 'cat_info' => 'all nature', 'cat_tags' => 'physics, chemistry' ); $keys = implode(', ', array_keys($data)); $values = ":".implode(", :", array_keys($data)); echo $sql = "insert $table($keys) values($values)"; $stmt = $this->db->prepare($sql); foreach ($data $key => $value) { $stmt->bindparam(':'.$key, $value); } return $stmt->execute(); }
database connection ok. because works on select , delete query, not working insert , update query. not want alternative want bug. please me. trying solve 2 days.
windows 10 64bit
wampserver 3.0.8
php 7.1
mysql 5.7
you need bindvalue()
instead of bindparam()
. change foreach loop to
foreach ($data $key => $value) { $stmt->bindvalue(':'.$key, $value); }
see doc:
http://php.net/manual/en/pdostatement.bindvalue.php
see difference here:what difference between bindparam , bindvalue?
Comments
Post a Comment