"My PHP script works on my server but it does not work on your server."

MySQL Connection

Sometimes, you may be wondering how to make your PHP script connect to the database that you have just got from us. By default, we set up your database in the same server as the web server. In addition, you might receive information like this from us:

===========================================================
MySQL ACCOUNT LOGIN INFO
===========================================================
Host : localhost
Database name : mydatabase_db
Username : mydbuser
Password : mydbpass
===========================================================

There are many ways to connect to the database. Here is just one example. The below is a simple example of how you can connect to your database, using the information we gave you above, do a simple query, and display the results in a table.

<?

/* declare some relevant variables */
$hostname = "localhost"; /* This is the hostname on which your MySQL is running */
$dbName = "mydatabase_db";
$username = "mydbuser";
$password = "mydbpass";
$table = "mytable"; /* MySQL table created to store the data */
/* Make connection to database */
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");

/* Select the database to be processed */
@mysql_select_db( "$dbName") or die( "Unable to select database");

/* Prepare the SQL query statement */
$query = "SELECT * FROM $table";

/* Execute the query */
$result = MYSQL_QUERY($query);

/* Now do something with the query result. e.g. print out the number of selected rows. */
$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$resid=mysql_result($result,$i,"ID");
$resname=mysql_result($result,$i,"Name");
$resage=mysql_result($result,$i,"Age");

echo "<br>$resid $resname $resage<br>";

$i++;
}

?>