passage entre mysqli et mysql
Bonjour,
j'aimerais bien changer mes extension de php : de MySql à MySqli
avec mysql_connect mon application marche :
Code:
1 2 3 4 5 6 7 8 9 10 11
| $db = mysql_connect("127.0.0.1", "login", "motdepasse" );
mysql_select_db("db_testUn",$db);
$query = mysql_query("SELECT COUNT(*) AS Combien FROM `matable` " );
if ($query)
{
$row = mysql_fetch_array($query);
echo '<center>Il y a '.$row["Combien"].' article(s) </center>';
} |
j'ai le bon compte avec le message suivant :
Citation:
il y a 23 article(s)
alors je transforme le code avec mysqli :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| //Open a new connection to the MySQL server
$mysqli = new mysqli('127.0.0.1','login','motdepasse','db_testUn');
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
//MySqli Select Query
//get total number of records
$query = "SELECT COUNT(*) AS Combien FROM matable";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if ($result)
{
/* Tableau associatif */
$row = $result->fetch_array($result);
echo '<center>Il y a '.$row["Combien"].' article(s) </center>';
}
// Frees the memory associated with a result
$results->free();
// close connection
$mysqli->close(); |
cela ne marche pas ::oops:
je n'ai pas le compte :
Citation:
il y a article(s)
Vous avez une idée ?
merci