Hi,

I create dbf.php file to connect database and require dbf.php in main.php but, doesn't work.

Thanks

dbf.php

<?php
$conn = mysql_connect('localhost', 'root', '');
if (!$conn) {
   	die('Could not connect: ' . mysql_error());
} else {
	mysql_select_db('dbf', $conn) or die('Could not select database.');
}
?>

main.php

<?php require '../dbf.php';?>

i think you didnt provide password on line:

$conn = mysql_connect('localhost', 'root', '');

or simply use this code below:

<?php
mysql_connect('localhost', 'username', 'password') ;
mysql_select_db('dbname');
?>
$dbhost = 'localhost';
   $dbuser = 'root';
   $dbpass = 'dbpassword';
   $dbname = 'databasename';
   $errorMessage = '';

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

   mysql_select_db($dbname);

  $sql = "      [B]QUERY    [/B]          ";

   $result = mysql_query($sql) 
             or die('Query failed. ' . mysql_error()); 

?>

Hi..
once try to do this.....may be it will help u..

you shoud seek out a tutorial on writting PHP classes. this will help you a lot in the future. it's good practice in my opinion to write it once and reuse it forever. building up a library of classes will help you not having to waste time rewriting or copy/pasting/modifiy'n

look around the web for a good PHP or PHP/MySQL cookbook, they are good sources for learning quickly and correctly.

hope this helps!

i will write database connections and other functions in one page and i will include in every page
so, there is no need of copy paste or modifications. i will surely take a look at php classes
if it is useful to me i will be grateful to u jel
thank u

This question has already been answered. Start a new discussion instead.