This example shows a simple conventional MySQL query of the authors database.
The statement specifying the connection system is:-
$conn = mysql_connect("localhost", $user, $pass)
The statement:-
mysql_select_db($dbname, $conn);
effects the connection to the "authors" database. Thereafter, php-provided
MySQL statements such as: mysql_list_fields(), mysql_num_rows(), mysql_fetch_row
and others make it easy to identify and display rows, field names and values,
row and field counts. Other statements are available for entering, deleting and
updating rows.
|
Contacts within the Authors Database: < ?php // Map authors database to physical path $dbname = "authors" ; $tblname = "authors"; $user = 'root'; $pass = ''; // Create ADO Connection Component to connect // with sample database $conn = mysql_connect("localhost", $user, $pass) or die(" Cannot connect to MySQL: " . mysql_error()); mysql_select_db($dbname, $conn); mysql_select_db($dbname, $conn); $fields = mysql_list_fields($dbname, $tblname, $conn); $sqlstr = "SELECT * From authors"; $query = "SELECT * From authors"; // Execute a SQL query and store the results // within recordset ?>
|