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
529 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 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 38749579
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
ID: 38749743
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
ID: 38749787
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38749854
Which version of PHP do you have?  As far as I know, all Windows versions are compiled with support for the MySQL drivers.
0
 

Author Comment

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

Expert Comment

by:Shaun_King_23
ID: 38750575
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
ID: 38750818
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
ID: 38753074
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
paypal ipn url 5 58
PHP AJAX JSON 2 61
Add email address from a web page to outlook 2010 contacts ? 8 28
Number of hours between date in DB and now 8 18
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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

810 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