This works in localhost on my PC, as well as localhost on the remote server:
connection.php
<?php
$server = "localhost";
$database = "somedatabase";
$username = "someuser";
$password = "somepassword";
$mysqlConnection = mysql_connect($server, $username, $password);
if (!$mysqlConnection)
{
echo "Please try later.";
}
else
{
mysql_select_db($database, $mysqlConnection);
}
?>
However, while this works in localhost on my PC, it doesn't work on localhost on the remote server (db.php
and connection2.php
are in the same folder). I get "Please try later" echoed out.
db.php
<?
$server = "localhost";
$database = "somedb";
$username = "someuser";
$password = "somepass";
?>
connection2.php
<?php
require("db.php");
$mysqlConnection = mysql_connect($server, $username, $password);
if (!$mysqlConnection)
{
echo "Please try later.";
}
else
{
mysql_select_db($database, $mysqlConnection);
}
?>
Thoughts?
Update: Per CharlesRojas' suggestion, I tried echoing out the variables in connection2.php
but nothing got echoed out. So, connection2.php
is not reading the contents in db.php
.
Update 2: I've added the solution below and will mark it as correct when I am able.