Sample Code : Query MySQL Database in PHP

<html>
<head><title>MySQL Test Code</title></head>
<body>
<h1>MySQL Test Code Results</h1>
<p>
<table border="1">
<tr><td>pkID</td><td>username</td><td>password</td></tr>
<?php

/*
 * Configuration Information and Definitions
*/
$mysql_host  = 'sql.yourdomain.com';
$mysql_user  = 'username';
$mysql_pass  = 'password';
$mysql_db    = 'database';
$query  = 'SELECT * from table1';

mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Connection to MySQL-server failed!");

mysql_select_db($mysql_db) or die("Selection of database $mysql_db failed!");

$result = mysql_query($query) or die("Invalid Query, " . mysql_error());

while( list( $pkid, $user, $pass ) = mysql_fetch_row($result) )
{
 printf("<tr><td>%d</td><td>%s</td><td>%s</td></tr>", $pkid, $user, $pass);
 
}

?>
</table>
</p>
<h1>End MySQL Test Code Results</h1>

 

Was this answer helpful?

 Print this Article

Also Read

I get this error when trying load my PHP page : "FATAL ERROR: register_globals is disabled in php.ini, please enable it!"

Register_Globals directive is set to OFF because of potential security issues.  PHP has this...

Sample Code : Sending mail via PHP

You can use PHPMailer to send mails via PHP. To use this open source object you need to download...

What is the path to Perl on the Servers?

The path is : #!/usr/bin/perl However! This is not require on the Windows platform, it is a Unix...