Il codice é qualcosa di simile a questo:
// connect to the database server - notice the '@' to suppress warning
$mysqli = @new mysqli("host", "user", "password");
if(mysqli_connect_error())
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
echo "Connection to MySql succeeded<br />";
echo "Selecting the current database schema: select_db() ... ";
$mysqli->select_db("mezzabar_test") or die($mysqli->error());
echo "OK<br />";
// Create the query
$query = "SELECT sku, name, price FROM products ORDER BY name";
echo "Performing a select: query(\"$query\") ... ";
if($rs = $mysqli->query($query))
echo "OK<br />";
else
die('Invalid query: ' . $mysqli->error());
echo "<br />List of available items:<br />";
// Iterate through the result set
while(list($sku, $name, $price) = $rs->fetch_row())
printf("(%s) %s: \$%s<br />", $sku, $name, $price);
// close the connection
if($mysqli->close())
echo "<br />Connection to MySql successfully closed<br />";
else
echo "<br />Error closing MySql connection<br />";
E può essere visto in azione qui.
Nessun commento:
Posta un commento