// $conn = connection object returned by mysqli_connect( ) call
if ( ( $result = mysqli_query( $conn, "SQL-command" ) ) == NULL )
{
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
// $result = the result set object returned by the query
|
Explanation:
|
/* -----------------------------------------
Make connection AND select "companyDB"
----------------------------------------- */
$conn = mysqli_connect("holland.mathcs.emory.edu","cs377", "abc123", "companyDB");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit(1);
}
/* -------------------------------------
Execute a select query
------------------------------------- */
$query = 'select fname, lname, salary from employee';
if ( ( $result = mysqli_query($conn, $query) ) == NULL )
{
// Returned a NULL object -- error
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
// We can retrieve the tuples in the result set using the $result variable !!
// Discussed NEXT !
|