Glover logo

On Line Databases


Home Glovers Contact Form

Pegasus Mail

Pegasus Mail Pmail Features

Pmail Extensions

Populist Delphi (1) Delphi (2) Dos Email

Digital Cameras

Digital images Renumber images Slideshows


Online Databases Access & ASP Access & PHP Mysql & ASP Mysql & PHP

Connection to MySQL databases - PHP scripting

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.

<HTML> <!--authphpmysql.php --> <HEAD><TITLE>Simple ADO Query</TITLE></HEAD> <BODY BGCOLOR="White" topmargin="10" leftmargin="10"> <!-- Display Header --> <font size="4" face="Arial, Helvetica"> <b>Simple MySQL Query with PHP</b></font><br /> <hr size="1" color="#000000" /> Contacts within the Authors Database:<br><br> < ?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("<br /><br />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 ?> <TABLE border = 1><tr bgcolor = '#DDEEAA'><th>ID</th><th>Author</th> <th>Year Born</th></tr> < ?php $columns = mysql_num_fields($fields); $result = mysql_query($sqlstr, $conn); // SQL SELECT all fields $recs = mysql_num_rows($result); $rowcount = 0; while($myrow = mysql_fetch_row($result)) // if theres stuff, go get it { echo "<tr bgcolor = '#CCEEFF'>"; for($i=0; $i < ($columns); $i++) { echo "<TD VAlign=top>" .$myrow[$i] ."</TD>"; } echo "</tr>"; $rowcount++ ; } ?> </TABLE> < ?php echo "Rowcount= " .$rowcount; $conn = null; ?> </BODY></HTML>

   Demo: Example of above code