Query MySQL Database in PHP

                                                        
1 <HTML>
2 <HEAD>
3
4 <H1>MySQL Test Code ResultsH1>
5 <P>
6 <TABLE border=1><TBODY><TR><TD>pkIDTD><TD>usernameTD><TD>passwordTD>TR>php
7
8 /*
9 * Configuration Information and Definitions
10 */
11 $mysql_host = 'mysql01.discountasp.net';
12 $mysql_user = 'username';
13 $mysql_pass = 'password';
14 $mysql_db = 'database';
15 $query = 'SELECT * from table1';
16
17 mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Connection to MySQL-server failed!");
18
19 mysql_select_db($mysql_db) or die("Selection of database $mysql_db failed!");
20
21 $result = mysql_query($query) or die("Invalid Query, " . mysql_error());
22
23 while( list( $pkid, $user, $pass ) = mysql_fetch_row($result) )
24 {
25 printf(" %d %s %s", $pkid, $user, $pass);
26
27 }
28
29 ?&gt;
30 TBODY>TABLE>
31 P>
32 <H1>End MySQL Test Code ResultsH1>
33

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Sample Code on how to send email using PHP

Part of what makes the PHP mail() function is so simple is its lack of flexibility. Most...

Query an MS SQL Database with PHP using DSNLess Connection

The information in this article applies to: PHP MS SQL 2000 MS SQL 2005...