我使用mysql的PDO预处理语句出现问题。
当查询执行时,它将保存到前置 使用 PHP(这是使用ajax调用的控制器)。 p>
PHP 2(这是管理所有数据库操作的类的功能) p>
这是查询执行后的结果屏幕
查询执行后的表格 p>
div> bindParam() code>方法表示我已绑定的占位符。
这是代码,这里是执行查询结果的屏幕。 我怎么能解决这个尴尬的问题? 我是PDO的新手! p>
if(isset( $ _POST ['code'])){
$ code = filter_var($ _ POST ['code'],FILTER_SANITIZE_STRING);
$ qty = filter_var($ _ POST ['quantity'],FILTER_SANITIZE_STRING);
$ brand = filter_var($ _ POST ['brand'],FILTER_SANITIZE_STRING);
$ article_name = filter_var($ _ POST ['artName'],FILTER_SANITIZE_STRING);
$ price = filter_var($ _ POST ['price'],FILTER_SANITIZE_STRING);
$ article_type = filter_var($ _ POST ['artType'],FILTER_SANITIZE_STRING);
$ note = filter_var($ _ POST ['note'],FILTER_SANITIZE_STRING);
$ save = $ core-> insert_article($ code,$ qty,$ brand,$ article_name,$ price,$ article_type,$ note);
if($ save){
echo'ok';
}其他{
echo'错误';
}
}
code> pre>
public function insert_article($ code,$ qty,$ brand,$ article_name,$ price,$ article_type,$ note){
$ db = $ this-> init_db();
$ sql =“INSERT INTO产品(cod_articolo,pezzi_disponibili,marca,nome_articolo,prezzo,tipologia_articolo,note)VALUES(':cod_articolo',':pezzi_disponibili',':marca',':nome_prodotto',': PREZZO”, ':tipologia_articolo', ':注意')“;
$ stmt = $ db-> prepare($ sql);
$的stmt-> bindParam( ':cod_articolo',$代码,PDO :: PARAM_STR);
$的stmt-> bindParam( ':pezzi_disponibili',$数量,PDO :: PARAM_STR);
$ stmt-> bindParam( ':马卡',$品牌,PDO :: PARAM_STR);
$的stmt-> bindParam( ':nome_articolo',$ ARTICLE_NAME,PDO :: PARAM_STR);
$的stmt-&GT ; bindParam( ':PREZZO',$价格,PDO :: PARAM_STR);
$的stmt-> bindParam( ':tipologia_articolo',$ article_type,PDO :: PARAM_STR);
$的stmt-> bindParam(” :note',$ note,PDO :: PARAM_STR);
if($ stmt-> execute()){
echo'ok';
}其他{
echo'错误';
}
}
code> pre>
I've a problem with PDO prepared statements using mysql.
When the query is executed it will save into the preposed table the placeholders that I've binded using the bindParam()
method.
Here is the code and here is a screen of the result of the execution of the query. How i can solve this embaracing problem? I'm a newbie on PDO!
PHP (This is the controller that is called using ajax).
if(isset($_POST['code'])){
$code = filter_var($_POST['code'],FILTER_SANITIZE_STRING);
$qty = filter_var($_POST['quantity'],FILTER_SANITIZE_STRING);
$brand = filter_var($_POST['brand'],FILTER_SANITIZE_STRING);
$article_name = filter_var($_POST['artName'],FILTER_SANITIZE_STRING);
$price = filter_var($_POST['price'],FILTER_SANITIZE_STRING);
$article_type = filter_var($_POST['artType'],FILTER_SANITIZE_STRING);
$note = filter_var($_POST['note'],FILTER_SANITIZE_STRING);
$save = $core->insert_article($code,$qty,$brand,$article_name,$price,$article_type,$note);
if($save){
echo 'ok';
} else {
echo 'error';
}
}
PHP 2 (this is the function of the class who manage all the database operations)
public function insert_article($code,$qty,$brand,$article_name,$price,$article_type,$note){
$db = $this->init_db();
$sql = "INSERT INTO products (cod_articolo, pezzi_disponibili, marca, nome_articolo, prezzo, tipologia_articolo, note) VALUES (':cod_articolo',':pezzi_disponibili',':marca',':nome_prodotto',':prezzo',':tipologia_articolo',':note')";
$stmt = $db->prepare($sql);
$stmt->bindParam(':cod_articolo',$code,PDO::PARAM_STR);
$stmt->bindParam(':pezzi_disponibili',$qty,PDO::PARAM_STR);
$stmt->bindParam(':marca',$brand,PDO::PARAM_STR);
$stmt->bindParam(':nome_articolo',$article_name,PDO::PARAM_STR);
$stmt->bindParam(':prezzo',$price,PDO::PARAM_STR);
$stmt->bindParam(':tipologia_articolo',$article_type,PDO::PARAM_STR);
$stmt->bindParam(':note',$note,PDO::PARAM_STR);
if($stmt->execute()){
echo 'ok';
} else {
echo 'error';
}
}
This is the screen of the results after that the query is executed table after query execution