For accessing MySQL 4.1 and up.
<?php
$link = mysqli_connect("localhost", "my_user", "psswd", "world");
if (mysqli_connect_errno()) {
echo "Connect failed: ".mysqli_connect_error();
exit();
}
if ($result = mysqli_query($link,"SELECT Name FROM City LIMIT 10")) {
printf("Select returned %d rows.\n", mysqli_num_rows($result));
while ($row = mysqli_fetch_row($result)) {
echo $row[0];
}
}
mysqli_close($link);
?>
<?php
$mysqli = new mysqli("localhost", "my_user", "psswd", "world");
if (mysqli_connect_errno()) {
echo "Connect failed: ".mysqli_connect_error();
exit();
}
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) {
printf("Select returned %d rows.\n", $result->num_rows);
while ($row = $result->fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
}
$mysqli->close();
?>
An Introduction to mysqli: Using MySQL 5 with PHP 5
Date: Thursday, August 4th, 2005
Time: 4:30pm - 5:15pm
Location: E141