Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 4th, 2006, 04:19 AM
Registered User
 
Join Date: May 2006
Location: Melbourne, Victoria, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default FATAL ERROR. Help me please???

Posted - 05/04/2006 : 09:16:47 AM


--------------------------------------------------------------------------------

Hi.

I have recently purchased "Beginning PHP5, APACHE, MySQL web development. by WROX". I'm a absolute newbie to these programs, and this book seemed best after browsing through a few books at the book shop. I have installed and set up all the programs as the book says too and have completed all the "Try It Out" exercises in chapter 2. I am now into chapter 3 and have typed the code for "creating a database" on page 94 & 95.

Now. My problem is, when I open up the page in IE I get this error message:
FATAL ERROR Call to underfined function mysql_connect() on line 4.

Line 4 in the code goes like this:

$connect = mysql_connect("localhost", "bp5am", "bp5ampass") or
die ("Hey loser, check your server connection.");

I have checked and mysql is running. I have checked the php.ini file to make sure the changes were correct. And now I'm here. Can anyone help me please.....



Reply With Quote
  #2 (permalink)  
Old May 4th, 2006, 04:21 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi stevie,

if your still there, hang on 10 min, im sorting you out.
Reply With Quote
  #3 (permalink)  
Old May 4th, 2006, 04:24 AM
Registered User
 
Join Date: May 2006
Location: Melbourne, Victoria, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx


Reply With Quote
  #4 (permalink)  
Old May 4th, 2006, 05:31 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi stevie,

the problem you are facing is that the mysql extension of your php is not being found properly. There can be several reasons for this, but lets start at the beginning. What you have to do first is the following:

Create a PHP file with the following line:
<?phpinfo()?>
(found that on this site, which, at first sight, i think looks quite informative:
http://www.thesitewizard.com/archive/php4install.shtml)

be sure to give it a .php extension and save it in your document root of apache, so you can access it trough a browser. When you do that, it prints all the info you might ever want on your php (OK, that's not true, but there is surely a lot in there that i have never even found out what it means).

At least there should be mention of the mysql extension there if it is running. If I recall right, there is a section in there showing the running extensions, and otherwise there is a section specifically for mysql.

Now, functions are defined in libraries. A lot of these libraries are bundled and installed in the php core, but mysql functions aren't anymore. This means you have to set up php to load these libraries to be able to access these functions.

Open your php.ini file, and check if you find this line:
;extension=php_mysql.dll
If you do, that's your problem. Remove the semicolon from the beginning of the line, and now php should load the extension.

Further there also is a section in the php.ini called [MySQL]. It might be educative to have a look in there, if you ever wanted to change some of those things.

A second possibility is that the extensions don't load. This happens when for example the directory specified here (also in php.ini) is incorrect:
extension_dir = "./"

. means the current dir, .. means the parent dir. Be sure not to give a full path here, because that doesn't work. If you have a subdirectory in your php folder called ext, you would for example use "./ext" or "/ext". However, if you run in to this problem, you should be notified when your web server starts, by a error message from php saying "unable to load extension at ...".

In general the undefined function error you get when you are calling a function that is not known to the php parser. you can get this by spelling mistake, or scope:
If you define a function in a conditional block (if block), you are not always able to call it. See http://php.net/manual/en/language.fu...s.user-defined
near Example 17-2 conditional functions for more explanation.

Now some more (unsolicited) advice. I you are using the php 5, consider using mysqli extension instead of mysql. It stands for mysql improved, and hasn't stolen it's name. the mysqli functions often carry almost the same name as their mysql companions, but are called mysqli_connect() for example. However another good advice I can give you is if you are serious about learning php, look up every function you intend to use in the php manual, that way you are sure it exists, what parameters it takes, and the manual often gives nice examples of how you can get most out of using certain functions in nifty or unexpected ways to do some interesting stuff. So basically, take your php manual and look up the mysqli extension and read about it... you won't regret.

If you are using php4, consider migrating to 5. It's also really an improvement. It's not at all hard to install, meaning it works in almost the same way as the 4.

Ok, there's just another couple of golden rules you must not forget:
  • Remember to restart apache after making changes to config files of php or apache.
  • The best book ever written about php is the manual!!! Really, it is my favorite php book. Lots of people have contributed to it, and it is really quite good. (way better than the mysql manual for example)if you don't have internet at home, you can download a compiled help file (.chm) containing most of it from the php.net
Reply With Quote
  #5 (permalink)  
Old May 5th, 2006, 09:11 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry,
that took longer than 10 min. Did it solve your problem though?

Reply With Quote
  #6 (permalink)  
Old May 6th, 2006, 04:38 AM
Registered User
 
Join Date: May 2006
Location: Melbourne, Victoria, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No worries mate. Thanks heaps for your effort!!! :-)
Stii no luck though. Had already changed paths for extension_dir and uncommented the line in the php.ini file. Created that phpinfo page and when I opened it in IE there was no info on mysql??? I tried un/re-installing mysql with the same result. I tagged the "i" after mysql with still no luck. Has anybody else had this same problem????????????

Reply With Quote
  #7 (permalink)  
Old May 7th, 2006, 03:35 AM
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Setvej1, what versions of PHP and MYSQL are you running and on what OS (winXP Mac Linux etc) ?

Reply With Quote
  #8 (permalink)  
Old June 8th, 2006, 12:36 PM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have the same problem. I've tried everything, including following the book's advice, including:
1) changing extension directory in php.ini to "c:\php\ext
2) uncommenting extension=php_mysql.dll
3) Copied libmysql.dll to c:\windows\system32 directory

I am running xp, Apache 2.0. PHP 5.03, MYSQL 4.01 (I believe)

Can someone help?

Reply With Quote
  #9 (permalink)  
Old June 9th, 2006, 04:52 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi;
There are some more possibilities. I had a look at home, and my extension folder which is just in the php directory, i called just "ext" in the ini file, after much swearing and searching. However, i was getting error messages when starting up apache because it wasn't finding the extensions. Have you been having error messages when starting apache?

Then if there is no mysql(i) section in phpinfo, for sure the extension is not loaded. don't have to install mysql again for that, in fact the php extension works also without mysql, but then you would get an error that it can't connect to the database, in which case you would know that the connect function is found. So for now, don't worry about mysql installation.

Something else i have done to make sure that libmysql(i).dll is being found by apache, is to put it in the bin directory of my apache installation.

An other thing you can do is adding the your php folder to the path if you are using windows.

If it is still not working, let us know, but be sure to pay attention to any error messages you get.
Reply With Quote
  #10 (permalink)  
Old February 22nd, 2007, 11:13 AM
Authorized User
 
Join Date: Feb 2007
Location: , , India.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Everybody,
I'am new to the WAMP (windowsxp + Apache + MySQL + php) based Web site and web applications developement. I have Apache 2.2, MySQL 5 and php 5.2.1 installed on my computer which is running on a xp home edition os.

The php programs which do not reqiure a database connection are easily running on my computer,( i.e the httpd.conf has got the LoadModule php5apache2_2 and phpts.dll is placed in the system32 dir.) . Also the mysql database running on my computer is working fine. But problem arises when i have to connect to the database using php via the function 'mysql_connect'.

I have followed the documentation on the php website regarding 'making php run with mysql' ( i.e i hav uncommented the extensions=php_mysql.dll & have changed the extension dir. path to C:\php\ext, and this is the correct path for my computer also i hav placed libmysql.dll in the system32 directory.)
After doing all the steps when i try to connect to the mysql database using the following code:--

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';

i get the following error message:--

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\test\createmovie.php on line 4

before coming to this forum i have also tried to use the extension php_mysqli.dll ( by uncommenting it in php.ini ) and placing the libmysql.dll in the system 32 directory with the extension dir. path as C:\php\ext but still i got the same error.

I have also tried to place the php folder in the system PATH , following the advice given on the php.net site , but still got the error.I have even tried out the latest versions of the libmysql.dll and php_mysql.dll files from the MySQL website But still it solves nothing.

i have read it in the book Beginning php5 that to make mysql work with php we have to use the libmysqli.dll file instead the libmysql.dll if the mysql version of 4.1 or later are being used , but the zip file i downloaded from the website php.net for php 5.2.1
hasnt got the file libmysqli.dll and on top of that the documentation on the website also advices to use the libmysql.dll file for the php_mysqli.dll extensions.

I'am kinda stuck on this thing , and this problem is preventing me from using php to its full potential.
this error has been givin me a headache ; Please, if anybody has got a solution scrap back on this thread, If u need any more clarification regardin the problem, just scrap in and i'll elaborate on it.

And also on someone's advice i tried using the forward slashes while defining my extensions_dir in the php.ini file. But still no solution.

>>>While opening the phpinfo(); in the browser i get that big php related file, but there's no mention of MySQL in it,,Also while restarting the Apache server i donot get any error regarding its inability to load any of the extensions....
Guys i have tried a lot and looked for the solution in many places, but still no results..
If someone knows how to solve this problem please help, ...
Thanking You,
Manu.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation FATAL ERROR bouca91 BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2 1 August 17th, 2008 01:57 PM
Fatal Error - A tough one! gargamel BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 April 4th, 2007 04:25 PM
Fatal Error?? dparsons ASP.NET 1.0 and 1.1 Professional 0 December 18th, 2006 01:55 PM
fatal error!!!! Ashleek007 Beginning PHP 6 October 9th, 2004 10:25 AM
Fatal error: singhzubin BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 April 11th, 2004 04:14 AM



All times are GMT -4. The time now is 10:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.