Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
553 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 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
Independent Software Vendors: 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 84

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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

604 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