"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:

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. */


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

while ($i < $num) {


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