删除整个表php pdo的奇怪字符
我有一个表(cod,nom),但nom字段有(')和(“)以及空格。 我想使用以下代码清理所有表:删除整个表php pdo的奇怪字符,php,mysql,pdo,Php,Mysql,Pdo,我有一个表(cod,nom),但nom字段有(')和(“)以及空格。 我想使用以下代码清理所有表: <?php class ConexionDB extends PDO { public function __construct () { try { parent:: __construct('mysql:host=localhost;dbname=xprueba;charset=utf8', 'root','key'); parent:: setAttri
<?php
class ConexionDB extends PDO {
public function __construct () {
try {
parent:: __construct('mysql:host=localhost;dbname=xprueba;charset=utf8', 'root','key');
parent:: setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $ex) { die ('Database is not exist'); } }
function __destruct(){
}
}
$BD = new ConexionDB();
$replace_these = ['"','\''];
$replace_with = ['',''];
$sql = "UPDATE xxx SET nom = :nom";
$sth = $BD->prepare($sql);
$nom = trim(str_replace($replace_these, $replace_with, :nom));
$sth->bindParam(':nom', $nom);
$sth->execute();
我假设第19行是:
$nom = trim(str_replace($replace_these, $replace_with, :nom));
因为您通过写入:nom
将变量$nom
拼写错误。请将其更改为:
$nom = trim(str_replace($replace_these, $replace_with, $nom));
它应该可以工作。顺便问一下,这个变量是干什么的?它没有在您提供的代码中的任何地方赋值。应该是什么?
:nom?这不是有效的PHP语法。我有一个包含数据(cod,nom)的表,nom字段需要清理,例如:nom1='ANGEL VEGA,nom2='JUAN“在运行我的代码之后,表是nom1=angelvega,nom2=JUAN。