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
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

734 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