logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Functions don't work, require once
Author
Piano_wamp



Joined: 25 May 2008
Posts: 3

PostPosted: Sun 25 May '08 23:30    Post subject: Functions don't work, require once Reply with quote

I've done my first istallation of Apache, PHP, and MySQL. Simple stuff seems to work OK.

However, when I try to use the require_once function, my error log says:

[Sun May 25 17:27:24 2008] [error] [client 127.0.0.1] PHP Warning: require_once(DB.PHP) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\test.php on line 12
[Sun May 25 17:27:24 2008] [error] [client 127.0.0.1] PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'DB.PHP' (include_path='.;C:\\php5\\pear') in D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\test.php on line 12


This has never worked and strikes me as a configuration issue.

I have tried unistalling and re-installing MySQL, but still get the same error. It's commented out now, but I also used to get a similar error on mysql_connect();

TYFYH
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 26 May '08 0:06    Post subject: Reply with quote

can you post an example code? ist the DB.PHP in the same folder?
Back to top
Piano_wamp



Joined: 25 May 2008
Posts: 3

PostPosted: Mon 26 May '08 0:12    Post subject: Reply with quote

TY, I can't find any DB.php file anywhere.

Here's the example code:


<?php

/*
phpinfo();

*/
require_once "DB.PHP";
require "db.inc";

$dbhost = 'localhost';
$dbuser = 'Admin';
$dbpass = 'admin';

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

$dbname = 'test';
mysql_select_db($dbname);

/*
require_once "DB.php";
require "db.inc";
$dsn = "mysql://Admin:admin@localhost/test";
print "{$dsn}";
*/

print "<p>END test<p/> </BODY>";
print "</html>";
?>
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 26 May '08 12:03    Post subject: Reply with quote

*g*
require!!(_once) means that there must be a db.php Wink

comment out that lines...

Where did you get that code?

very short working example

Code:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


See the docs for more details

http://www.php.net/mysql_connect
http://www.php.net/require
Back to top
Piano_wamp



Joined: 25 May 2008
Posts: 3

PostPosted: Mon 26 May '08 23:50    Post subject: Reply with quote

TY.

Code came from O'Reilly's "PHP and MySQL" - 2nd edition.

Tried your code. It worked at least until the point of getting an Access denied for user message, but that's probabl something else. At least the function was called.

Shouldn't DB.php have come down with the PHP download? Or is this something obsolete in PHP5. PHP5 was only in beta at the time the book was published, so it's mostly about PHP4. I'm pretty sure I did a full sownload with options maxed. Maybe an uninstall and re-install?
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Tue 27 May '08 2:13    Post subject: Reply with quote

You do need to reinstall PHP.
I suspect that the DB.php file from the example may come from PEAR (PHP repository of reusable code). In any case, please do not learn outdated stuff. Look at PHP manual or Zend Framework examples.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 27 May '08 11:37    Post subject: Reply with quote

alex.w474 wrote:
You do need to reinstall PHP.

That is not true!! PHP works fine! There is missing a php file not something from the installation. if you realy need pear you can install it by using go-pear.bat inside the PHP folder. Or install it by hand.
If you need Zend Framework you can download it on the zend page.

Don't reinstall PHP!

Please read the O'Reilly's "PHP and MySQL" what you need to run that code!
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Tue 27 May '08 15:37    Post subject: Reply with quote

I'm frustrated because of my mind. Of course "You do NOT need to reinstall PHP". I'm sorry for the mistype.
Back to top


Reply to topic   Topic: Functions don't work, require once View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner