php require problem

Thread Solved

Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

php require problem

 
0
  #1
Jul 31st, 2008
Hi,

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

Thanks

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

main.php
  1. <?php require '../dbf.php';?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: php require problem

 
0
  #2
Jul 31st, 2008
i think you didnt provide password on line:
  1. $conn = mysql_connect('localhost', 'root', '');
or simply use this code below:
  1. <?php
  2. mysql_connect('localhost', 'username', 'password') ;
  3. mysql_select_db('dbname');
  4. ?>
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: saikishore is an unknown quantity at this point 
Solved Threads: 7
saikishore saikishore is offline Offline
Light Poster

Re: php require problem

 
0
  #3
Jul 31st, 2008
 $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 = "      QUERY              ";

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

?>

Hi..
once try to do this.....may be it will help u..
With Regards,
Kishore
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 18
Reputation: jel3 is an unknown quantity at this point 
Solved Threads: 3
jel3's Avatar
jel3 jel3 is offline Offline
Newbie Poster

Re: php require problem

 
0
  #4
Aug 1st, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 171
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 21
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: php require problem

 
0
  #5
Aug 2nd, 2008
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
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC