Return to Snippet

Revision: 25797
at April 9, 2010 08:14 by alexandrepayet


Initial Code
<?php

/* how to create connexion (4th parameter = default database) */
$mysqli = new mysqli($host, $usr, $pass, $db);

/* how to verify connexion */
if (mysqli_connect_errno()) {
    printf("Echec de la connexion : %s\n", mysqli_connect_error());
}

/* how to set the default charset to use */
if (!$mysqli->set_charset("utf8")) {
   printf("Erreur lors du chargement du jeu de caractères utf8 : %s\n", $mysqli->error);
}

/* how to use real_escape_string on string */
$nom = $mysqli->real_escape_string($nom);
$mail = $mysqli->real_escape_string($mail);
$tel = $mysqli->real_escape_string($tel);


/*how to get data in a table with a while */
$query = "SELECT nom, mail, tel FROM ufr_jury ORDER by nom;";
$ressource = $mysqli->query($query);
while($result = $ressource->fetch_assoc()){
						
	echo "<tr>";
							
	echo "<td>".$result['nom']."</td>";
	echo "<td>".$result['mail']."</td>";
	echo "<td>".$result['tel']."</td>";
							
	echo "</tr>";

}

/* how to free result ressource */
$ressource->close();
						
/* how to close connection */
$mysqli->close();

?>

Initial URL

                                

Initial Description

                                

Initial Title
PHP : Utilisation de mysqli (syntaxe objet)

Initial Tags
database, php, object

Initial Language
PHP