Solved

Fatal error: Call to undefined function mysql_connect() in C:\Chapter23\fig23_14_15\database.php on line 30

Posted on 2013-01-06
8
522 Views
Last Modified: 2013-01-07
Hi am taking a  computer science Web course correspondence and need a little help.
I installed Apache 2.0,  PHP 5 and MySQL on my Window 7 computer.  I am using the text 4th Edition Internet & World Wide Web How to Program and in Chapter 23.5 entitled Connecting to a Database you are asked to execute the attached Products script which I did successfully.  The attached data.html file is an example of Querying a MYSQL database.  When I Select a field to display and then send the Query

http://localhost/phpscripts/fig23_14_15/database.php returns

Fatal error: Call to undefined function mysql_connect() in C:\Chapter23\fig23_14_15\database.php on line 30

and in the error log in apache shows the following for the incident:

[Sun Jan 06 18:12:09 2013] [client 127.0.0.1] File does not exist: C:/Apache/Apache2/htdocs/favicon.ico
[Sun Jan 06 18:12:15 2013] [client 127.0.0.1] PHP Fatal error:  Call to undefined function mysql_connect() in C:\\Chapter23\\fig23_14_15\\database.php on line 30, referer: http://localhost/phpscripts/fig23_14_15/data.html
[Sun Jan 06 18:12:15 2013] [client 127.0.0.1] File does not exist: C:/Apache/Apache2/htdocs/favicon.ico

My thinking is that I don't have MYSQL configured to work with Apache am I correct.  Please help
data.html
database.php
Products.sql
0
Comment
Question by:Genus1
8 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
Comment Utility
In 'php.ini', you need to enable the 'php_mysql.dll' extension by removing the ';' in front of it and restarting the server.
0
 

Author Comment

by:Genus1
Comment Utility
I removed the semicolon as seen in the attached file.  Stopped and restarted the server.  I still got the same error.
php.ini
0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
Comment Utility
Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page for MySQL. If you don't see it, you need to recompile PHP with MySQL support,
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Which version of PHP do you have?  As far as I know, all Windows versions are compiled with support for the MySQL drivers.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Genus1
Comment Utility
I downloaded and installed php-5.2.17-Win32-VC6-x86.zip .
0
 
LVL 1

Expert Comment

by:Shaun_King_23
Comment Utility
try initialising $database first

<?php

extract( $_POST );

$database = mysql_connect('localhost', 'iw3htp4', 'iw3htp4');

// build SELECT query
$query = "SELECT " . $select . " FROM books";

// Connect to MySQL
if (!$database) {
    die('Could not connect: ' . mysql_error());
}
// open Products database
if ( !mysql_select_db( "products", $database ) )
  die( "Could not open products database </body></html>" );

// query Products database
if ( !( $result = mysql_query( $query, $database ) ) ) 
    {
        print( "Could not execute query! <br />" );
        die( mysql_error() . "</body></html>" );
     } // end if

mysql_close( $database );
?>

Open in new window


also is the username and password correct.

hope this helps.
0
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 250 total points
Comment Utility
If MySQL isn't loaded when you run the phpinfo script, check to see if any of the extensions are loaded.  Based on your php.ini file your extension directory is set to  ./  

In your php.inin file you need to put in the path to your extension directory so it can find the php_mysql.dll.  This is what mine looks like....

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/LAMP/php53/ext"

Open in new window


You will want to change the path to point to your ext directory.  Using ./ on my system gave me the same undefined function error you are getting.
0
 

Author Closing Comment

by:Genus1
Comment Utility
That did it.  So just to be clear I had to make the following edits in the php.ini file to resolve the issue:

1: Enable the 'php_mysql.dll' extension by removing the ';' in front of it and restarting the server.

2:  Put in the correct path for my extension_dir.

Thanks so much :) !
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now