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
524 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

896 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

14 Experts available now in Live!

Get 1:1 Help Now