connect_errno) {
// connect_error returns the a string of the error from the latest sql command
print (" There was an error:
" . $db_server->connect_error . "
");
} else {
// We successfully connected to the database
// The query is a php string
$customers_query = "SELECT * FROM customers";
// query executes an sql query
$customers_result = $db_server->query($customers_query);
if (!$customers_result) {
/* If there was an error executing the query, the result will be false,
otherwise its a mysql result resource. */
print (" There was an error:
" . $db_server->connect_error . "
");
} else {
// num_rows returns the number of rows resulting from a query
$num_customers = $customers_result->num_rows;
print (" Our Customers
");
print "";
for ($cur_customer_num = 0; $cur_customer_num < $num_customers; $cur_customer_num++){
// data_seek goes to the specified row of a query result
$customers_result->data_seek($cur_customer_num);
// fetch_assoc returns the current row as an associative array
$cur_customer = $customers_result->fetch_assoc();
print_customer($cur_customer);
}
}
}
// You should always close server connections when you're done
$db_server->close();
if ($db_server->connect_errno) {
// connect_error returns the a string of the error from the latest sql command
print (" There was an error:
" . $db_server->connect_error . "
");
}
function print_customer ($customer) {
print "";
}
?>