I wrote a function to insert what i want in any database :
public function insert($db, $array_label, $array_value){
$DB = new PDO('mysql:host='.$_SESSION['mysql'][0].';dbname='.$_SESSION['mysql'][1].';charset=utf8', $_SESSION['mysql'][2], $_SESSION['mysql'][3]);
$sql = "INSERT INTO '".$db."' (";
for($i = 0; $i < count($array_label); $i++){
if($i > 0)
$sql .= ", ";
$sql .= "'".$array_label[$i]."'";
}
$sql .= ") VALUES (";
for($i = 0; $i < count($array_label); $i++){
if($i > 0)
$sql .= ", ";
$sql .= ":".$array_label[$i];
}
$sql .= ")";
$stmt = $DB->prepare($sql);
echo '\$DB->prepare("'.$sql.'");';//DEBUG
for($i = 0; $i < count($array_label); $i++){
$label = ":".$array_label[$i];
$stmt->bindParam("$label", $array_value[$i]);
echo '</br>\$stmt->bindValue("'.$label.'", '.$array_value[$i].')';//DEBUG
}
$stmt->execute;
echo "</br></br>Requête OK.";
}
}
Then, i use it like this :
$array_label = array('ID', 'ID_lang', 'ID_entry_cat', 'date', 'label', 'content');
$array_value = array($ID, $ID_lang, $ID_entry_cat, "2016-03-03 00:00:00", $label, $content);
$DB->insert('entry', $array_label, $array_value);
After doing a lot of test, it may have a syntax problem, but i wasn't able to figure out where.
Here is what i got from the echo's(//DEBUG) :
$DB->prepare("INSERT INTO 'entry' ('ID', 'ID_lang', 'ID_entry_cat', 'date', 'label', 'content') VALUES (:ID, :ID_lang, :ID_entry_cat, :date, :label, :content)");
\$stmt->bindValue(":ID", 1)
\$stmt->bindValue(":ID_lang", 1)
\$stmt->bindValue(":ID_entry_cat", 1)
\$stmt->bindValue(":date", 2016-03-03 00:00:00)
\$stmt->bindValue(":label", dsqfsdq)
\$stmt->bindValue(":content", sdqfdsqf)
I know there is plenty topics on PDO not returning error but : After reading a lot of them, it didn't help me at all. Let say this : I'm a complete noob with PDO.
The echo i showed to you is what my function is doing.
I enclosed some pictures of my db to help :
PS: i leaved out "date" but it's not supposed to make troubles. I tested the same thing with it and it did the same thing : nothing.