ubtimmay Posted March 29, 2007 Share Posted March 29, 2007 Hey all, New to the forum. I'm learning PHP MySQL so I'm sorry if this is something thats been brought up before. I'm using the O'Reilly "Learning PHP & MySQL" book and I've come to the section about using PEAR's DB module. They provided a 30 or so line of code to test if DB was installed and I'm getting an error. But in my phpinfo.php file it says PEAR is enabled so I'm at a loss for conclusions. Any help would be great. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <?php include('db_login.php'); require_once('DB.php'); $connection = DB::connect("mysql://$db_username:$db_password@db_host:db_database"); if (DB::isError($connection)){ die("Could not connect to the database: <br />".DB::errorMessage($connection)); } $query = "SELECT * FROM 'books' NATURAL JOIN 'authors'"; $result = $connection->query($query); if (DB::isError($result)){ die("Could not query the database:<br />".$query." ".DB::errorMessage($result)); } echo('<table border="1">'); echo '<tr><th>Title</th><th>Author</th><th>Pages</th></tr>'; while ($result_row = $result->fetchRow()) { echo "<tr><td>"; echo $result_row[1] . '</td><td>'; echo $result_row[4] . '</td><td>'; echo $result_row[2] . '</td></tr>'; } echo("</table>"); $connection->disconnect(); ?> </body> </html> PHP Info: http://www.blankdiscmedia.com/newhtml/phpinfo.php The Page: http://www.blankdiscmedia.com/newhtml/db_test.php The Error: Warning: require_once(DB.php) [function.require-once]: failed to open stream: No such file or directory in /home/bdmedia/public_html/newhtml/db_test.php on line 12 Fatal error: require_once() [function.require]: Failed opening required 'DB.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bdmedia/public_html/newhtml/db_test.php on line 12 Thanks from a php newbie Tim Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/ Share on other sites More sharing options...
MadTechie Posted March 29, 2007 Share Posted March 29, 2007 DB.php doesn't exist in http://www.blankdiscmedia.com/newhtml/ check you uploaded it Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-217489 Share on other sites More sharing options...
ubtimmay Posted March 29, 2007 Author Share Posted March 29, 2007 Where do I get DB.php from? Maybe I'm just not reading this right but O'Reilly makes it sound like a Class thats included in PEAR and I'm just referencing it. Seriously they just bring it up without what seems to be an instruction on how its supposed to get in my folder in the first place. This is important to me because I'm trying to learn on my own with the book and the book uses this "DB" class to access the database in all its examples for the rest of the book. ??? Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-217636 Share on other sites More sharing options...
genericnumber1 Posted March 29, 2007 Share Posted March 29, 2007 They probably presented it at some point, but as he said... it's not a core part of php. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-217639 Share on other sites More sharing options...
ubtimmay Posted March 29, 2007 Author Share Posted March 29, 2007 Grrrrr speed bumps, I'll take a look back tonight. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-217659 Share on other sites More sharing options...
ubtimmay Posted March 30, 2007 Author Share Posted March 30, 2007 This is what I found in the book The file DB.php is found in the /pear subdirectory of the PHP distribution. The PEAR install should have added that directory to the include_path in the php.ini file. If this file is not found, verify that PEAR DB is installed and that the paths are set up correctly. This isn't a file I'm supposed to create myself, it's a file PEAR provides with a class of DB within it that has predefined connect functions. So if PEAR is installed on my server then the php.ini file must not have the right include_path? Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-217862 Share on other sites More sharing options...
neel_basu Posted March 30, 2007 Share Posted March 30, 2007 You Can Do Something like that over here. Download the files that holds the class. From here http://zigmoyd.sourceforge.net/man/db.php#browse Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218105 Share on other sites More sharing options...
ubtimmay Posted March 30, 2007 Author Share Posted March 30, 2007 I guess I just don't understand if using DB.php is so common in PHP coding and writing database query scripts why can nobody answer my question? Is the DB class and fetchRow function commonly used or is the mysql_connect command more popular? I'm just looking for somebody who uses the DB class to tell me how they know the file is there or where I can get it or what it does or anything. Or if DB is working but I haven't created a proper DB file, what is the script I need to put in the DB file? I appreciate the workarounds, but I would like to not do a workaround, I want DB to work, it seems the rest of the code works just fine except for trying to access the DB class. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218169 Share on other sites More sharing options...
ubtimmay Posted March 30, 2007 Author Share Posted March 30, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218262 Share on other sites More sharing options...
ubtimmay Posted March 31, 2007 Author Share Posted March 31, 2007 update: my server guy reinstalled the PEAR DB package, added a path to php.ini and now I get the error: Fatal error: Class 'DB' not found in /home/bdmedia/public_html/newhtml/db_test.php on line 14 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <?php include('db_login.php'); require_once('DB.php'); $connection = DB::connect("mysql://$db_username:$db_password@$db_host/$db_database"); if (DB::isError($connection)){ die("Could not connect to the database: <br />".DB::errorMessage($connection)); } $query = "SELECT * FROM 'books' NATURAL JOIN 'authors'"; $result = $connection->query($query); if (DB::isError($result)){ die("Could not query the database:<br />".$query." ".DB::errorMessage($result)); } echo('<table border="1">'); echo '<tr><th>Title</th><th>Author</th><th>Pages</th></tr>'; while ($result_row = $result->fetchRow()) { echo "<tr><td>"; echo $result_row[1] . '</td><td>'; echo $result_row[4] . '</td><td>'; echo $result_row[2] . '</td></tr>'; } echo("</table>"); $connection->disconnect(); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218462 Share on other sites More sharing options...
neel_basu Posted March 31, 2007 Share Posted March 31, 2007 OK Would I make a Script For You that will run in all platform ?? Respond Quickly!! Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218510 Share on other sites More sharing options...
ubtimmay Posted March 31, 2007 Author Share Posted March 31, 2007 I'm just wondering what that new error means, I think its something my server guy needs to set since I've looked up and down my code and I can't find anything wrong with how I'm calling DB Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-218522 Share on other sites More sharing options...
ubtimmay Posted April 1, 2007 Author Share Posted April 1, 2007 Nobody's ever seen this error? Fatal error: Class 'DB' not found in /home/bdmedia/public_html/newhtml/db_test.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219167 Share on other sites More sharing options...
neel_basu Posted April 1, 2007 Share Posted April 1, 2007 But I dont understand why you are using PEAR DB Classes How much EXTRA you are getting. If you are not getting something Extra why You are Using It.???????? ??? ??? Cause Its also possible to do this job without PEAR DB very easily. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219173 Share on other sites More sharing options...
ubtimmay Posted April 1, 2007 Author Share Posted April 1, 2007 because I'm learning from a book that uses it, i'm trying to do the same connection functions using mysql_connect and I'm having some success, but that doesn't mean I shouldn't learn DBs more compact functionality for farther down the road does it? I realize that this particular code is simple, but thats the point its simply a test to see if DB is installed and working correctly so for the rest of the book I can work with the DB class to connect and call fetchrow functions and whatnot and follow along. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219224 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 because I'm learning from a book that uses it either get a better book are go back over thr chapters you skipped Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219230 Share on other sites More sharing options...
neel_basu Posted April 1, 2007 Share Posted April 1, 2007 Tell Whats The Code On the book Tries to Do We are converting it to real php. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219243 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 no, no, he wants do to it the book way.. other options were offered.. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219245 Share on other sites More sharing options...
ubtimmay Posted April 1, 2007 Author Share Posted April 1, 2007 sarcasm is always appreciated. thanks for the derailment, it was very helpful, if anything at least it bumped my thread a few times. Is O'Reilly not the standard for learning PHP? I recall a few classes in college that used O'Reilly's books, sorry if the book doesn't live up to your standards. I don't see how my servers settings have anything to do with my book or my code. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219356 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 I'm an O'Reilly fan.. but skipping chapters doesn't work.. plus the Pear chapter does state in addition to database access and templates, we also explain how to install PEAR packages and ..... in addition to your comment I don't see how my servers settings have anything to do with my book or my code. again from the O'Reilly book about PEAR if you find that you PHP engine can't find DB.php, it's likely that your include_path directive in your php.ini configuration file doesn't include the PEAR directory, Check the installation ..... so i say again read the chapter again or any you missed Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219380 Share on other sites More sharing options...
yzerman Posted April 1, 2007 Share Posted April 1, 2007 I think you need to read up on error codes, as it tells you exactly what is wrong, and where: this is line 14: $connection = DB::connect("mysql://$db_username:$db_password@$db_host/$db_database"); This is the error: Fatal error: Class 'DB' not found in /home/bdmedia/public_html/newhtml/db_test.php on line 14 My **guess** would be that you are calling an undefined class (DB) with the command DB::connect. Find out where that class is supposed to be defined, and include that file into this script. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219389 Share on other sites More sharing options...
ubtimmay Posted April 2, 2007 Author Share Posted April 2, 2007 I'm an O'Reilly fan.. but skipping chapters doesn't work.. plus the Pear chapter does state in addition to database access and templates, we also explain how to install PEAR packages and ..... I'm using an ISP with this already installed. I didn't skip the chapter, I don't know how to control my PEAR list on my ISP host, my server guy already changed the include path in the php.ini file. Furthermore O'Reilly doesn't say how to log into an ISP using Terminal to install PEAR or adjust its settings, it only has instructions for local installation, so sorry I can't pull that info out of nowhere, i've already stated I'm a beginner learning from scratch. in addition to your comment I don't see how my servers settings have anything to do with my book or my code. again from the O'Reilly book about PEAR if you find that you PHP engine can't find DB.php, it's likely that your include_path directive in your php.ini configuration file doesn't include the PEAR directory, Check the installation ..... In my first error it was saying that DB.php was not found, after we switched the include_path now we get the Fatal Error which is completely different as far as I know, which is my current question. What is this error or how is it the same as the file DB.php not found? so i say again read the chapter again or any you missed I can read it 4 more times than the 3 I already have, just because I came here for auxilary support and understanding doesn't mean I skipped chapters. To what yzerman said: Am I not understanding this right that the DB Class is pre-defined in DB.php within the DB package of PEAR? Thats the whole reason PEAR is installed and used in the first place isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219471 Share on other sites More sharing options...
yzerman Posted April 2, 2007 Share Posted April 2, 2007 When they installed PEAR, did they also install the PEAR DB? ssh into your box, and use the command: pear install db and make sure that the path to the pear-db package is in the include_path in your php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219858 Share on other sites More sharing options...
ubtimmay Posted April 2, 2007 Author Share Posted April 2, 2007 I'm pretty sure he did, but regardless hes going to reinstall php and pear today and check the php.ini include_path again and we're going to try it again tonight or tomorrow and see if the error shows up still. I'll post back. If that doesn't work I'll post on the Pear Forums and see if anyone there has any such difficulty with PEAR installs online. Quote Link to comment https://forums.phpfreaks.com/topic/44793-dbphp-error/#findComment-219894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.