943,974 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1895
  • PHP RSS
Jul 31st, 2008
0

php require problem

Expand Post »
Hi,

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

Thanks

dbf.php
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. <?php require '../dbf.php';?>
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Jul 31st, 2008
0

Re: php require problem

i think you didnt provide password on line:
PHP Syntax (Toggle Plain Text)
  1. $conn = mysql_connect('localhost', 'root', '');
or simply use this code below:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. mysql_connect('localhost', 'username', 'password') ;
  3. mysql_select_db('dbname');
  4. ?>
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 31st, 2008
0

Re: php require problem

 $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..
Reputation Points: 10
Solved Threads: 7
Unverified User
saikishore is offline Offline
41 posts
since Jul 2008
Aug 1st, 2008
0

Re: php require problem

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!
Reputation Points: 12
Solved Threads: 3
Newbie Poster
jel3 is offline Offline
18 posts
since May 2008
Aug 2nd, 2008
0

Re: php require problem

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
Reputation Points: 21
Solved Threads: 29
Posting Whiz in Training
praveen_dusari is offline Offline
202 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: forget password
Next Thread in PHP Forum Timeline: Downloaded file show 0byte





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC