Php include problem

Hi.

I am doing a website and I would like to include a file where it will include php code for connect to mysql server and selecting my mysql database.

So the file is something like (connection.php) :

[code]<?php
$dbhost = ‘db.php-mysql-tutorial.com:3306’;
$dbuser = ‘root’;
$dbpass = ‘password’;

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);

$dbname = ‘petstore’;
mysql_select_db($dbname);
?>[/code]

However, when I include this file into my other pages (e.g. at login.php), it does not connect to the mysql server. I get errors similar to those when the code of connecting to the mysql server is not included.

The include command I use is:

<?php include("connection.php"); ?>

Any ideas what the problem might be?

Hi there,

Does any of the errors inform you of a file include error like couldn’t include file connect.php, etc? If none of the errors were include related, it has something to do with your database connection. If you are getting errors regarding the including of the file, check the location of the included file in relation to the file you are adding the include statement in and make sure you are pointing to the right directory to where the file is to be included.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service