Actualy这是我用php执行sql select的代码:
$bdd = new PDO('mysql:host=localhost;dbname=spb', 'root', '');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$table = explode(" where",explode("from ",$test)[1])[0];
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table';";
$req = $bdd->query($sql);
$retour = "<table><tr><th></th><th>N° ligne</th>";
$titres = array();
while($resultat = $req->fetch()){
array_push($titres,$resultat['COLUMN_NAME']);
$retour.="<th>".$resultat['COLUMN_NAME']."</th>";
}
$retour.= "</tr>";
$req = $bdd->query($requette);
$cpt = 0;
$nbLigne = 0;
while($resultat = $req->fetch()){
$nbLigne++;
$retour .= "<tr><td class='boutonTouteLaCase' onclick='surlignerLigneProjets(this);'></td><td>$nbLigne</td>";
for($cpt=0;$cpt<count($titres);$cpt++){
$retour .= "<td>".$resultat[$titres[$cpt]]."</td>";
}
$retour .= "</tr>";
}
return $retour."</table>";
它正在为这种需求工作:select * from utilisateurs
但是当我添加这样的扩展程序时:select id from utilisateurs
或select * from utilisateurs order by prenom
。
它不起作用:/
任何的想法 ? THX
编辑:问题是:如何在字符串中执行sql req?