}
function desc_table($table_name){
- $sql = "SELECT * from information_schema.columns where table_name='".$table_name."'";
- $rst = $this->query($sql);
+ if(strpos($table_name, "'") !== false){
+ throw new Exception($this->exception_out("nom de table avec un simple quote"));
+ }
$desc = array(
"name" => $table_name,
"attributs" => array()
);
+ $sql = "PRAGMA table_info(".$table_name.")";
try{
- while($v_rst = $this->fetch_assoc($rst)){\r
- $desc["attributs"][$v_rst["COLUMN_NAME"]] = array(
- "name" => $v_rst["COLUMN_NAME"],
- "prymary_key" => $v_rst["COLUMN_KEY"] == "PRI" ? true : false,
- "auto_increment" => $v_rst["EXTRA"] == "auto_increment" ? true : false
+ $rst = $this->query($sql);
+ while($v_rst = $this->fetch_assoc($rst)){
+ $desc["attributs"][$v_rst["name"]] = array(
+ "name" => $v_rst["name"],
+ "prymary_key" => isset($v_rst["pk"]) && $v_rst["pk"] ? true : false
);
- }\r
+ }
$this->free_result($rst);
}
catch(Exception $e){
- throw new Exception($this->exception_out("Impossible de lire la description de la table"));
+ throw new Exception($this->exception_out("impossible de lire les champs de la table ".$table_name));
}
return $desc;
}