Pas d'erreur et pourtant la base est vide
Résolu
Utilisateur anonyme
-
Utilisateur anonyme -
Utilisateur anonyme -
Salut !
Je me remets au PHP MySQL. Il y a du changement en MySQL depuis 2008.
Pour commencer mysql_* est apparemment aux oubliettes. Alors j'ai cherché du code pour savoir comment insérer des données. Pas simple !
Voici mon code :
$Connexion=Mysqli_Connect("localhost", "root", "","u178618735_cours");
If (Mysqli_Connect_Errno())
{
Die("Echec de connexion : ".Mysqli_Connect_Error());
}
Mysqli_Query($Connexion, "INSERT INTO participants (ID, Nom, Password) VALUES ('', $Nom, $PWD)");
Mysqli_Close($Connexion);
Les variables sont "Ok" il y a bien une valeur mais lorsque je regarde dans PHP My Admin, il n'y a rien. Pourtant, je n'ai pas d'erreur.
Ou sont passés les données ?
Par ailleurs, comment tester si Mysqli_Query a bien fait son travail ? Merci
Je me remets au PHP MySQL. Il y a du changement en MySQL depuis 2008.
Pour commencer mysql_* est apparemment aux oubliettes. Alors j'ai cherché du code pour savoir comment insérer des données. Pas simple !
Voici mon code :
$Connexion=Mysqli_Connect("localhost", "root", "","u178618735_cours");
If (Mysqli_Connect_Errno())
{
Die("Echec de connexion : ".Mysqli_Connect_Error());
}
Mysqli_Query($Connexion, "INSERT INTO participants (ID, Nom, Password) VALUES ('', $Nom, $PWD)");
Mysqli_Close($Connexion);
Les variables sont "Ok" il y a bien une valeur mais lorsque je regarde dans PHP My Admin, il n'y a rien. Pourtant, je n'ai pas d'erreur.
Ou sont passés les données ?
Par ailleurs, comment tester si Mysqli_Query a bien fait son travail ? Merci
1 réponse
-
-
-
-
Sorry mais je ne vois pas trop...
En fait j'utilise plutôt PDO. Ca fonctionne très bien et c'est plus sécurisé.
Voici un exemple :
function connectDB() {
try {
$dsn = 'mysql:host=localhost;dbname=Nom_Base_de_donnees';
$dbh = new PDO($dsn, 'login_mysql', 'mot_de_passe', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch (PDOException $e)
{
$dbh = FALSE;
}
return $dbh;
}
// strSQL = Requête SQL
function selectDB($strSQL){
$dbh = connectDB();
if($dbh === FALSE) {
return FALSE;
}
else {
try {
$sth = $dbh->query($strSQL);
if ($sth === FALSE)
{
return FALSE;
}
else {
$result = $sth->fetchAll(PDO::FETCH_BOTH);
return $result;
}
}
catch(Exception $e) {
return FALSE;
}
}
}
function updateDB($strSQL){
$dbh = connectDB();
if($dbh == FALSE) {
return FALSE;
}
else {
try {
$requete = $dbh->exec($strSQL);
return $requete;
}
catch (Exception $e) {
return FALSE;
}
}
}
Sais pas si ça peut t'aider. -
-
-
