Fatal error: Call to undefined function mysql_connect() in /Users/praveenvasireddy/localhost/test/test2.php on line 2

I am a newbie to LAMP stack. I beleive I have setup apache,php and mysql correctly.


Modified php.ini to include mysql.default_socket = /tmp/mysql.sock


Modified httpd.conf to enable php module.


When I run a webpage with phpinfo(), below is a snippet from the same.


mysqlnd


mysqlnd enabled
Version mysqlnd 5.0.8-dev - 20102224 - $Id: 65fe78e70ce53d27a6cd578597722950e490b0d0 $
Compression supported
SSL supported
Command buffer size 4096
Read buffer size 32768
Read timeout 31536000
Collecting statistics Yes
Collecting memory statistics Yes
Tracing n/a



Code which fails is on line 2 of the test page.


<?php

$con = mysql_connect("127.0.0.1","root","");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

$fname = $_POST["fname"];

$lname = $_POST["lname"];

$add1 = $_POST["add1"];

...

...


FYI ... prior to setting up apache,php and mysql seperately I tried XAMPP and the same code back worked.


Please help me what need to get configured to make sure that php connects to localhost mysql.


Thank you in advance.

MacBook Pro with Retina display, OS X Mountain Lion (10.8.2)

Posted on Nov 28, 2012 12:51 AM

Reply
2 replies

Nov 28, 2012 4:36 AM in response to pvasireddy

did you enable mysql in php.ini? it's not enabled by default. search php.ini for the following text:


extension=php_mysql.dll


if there's a semicolon at the begining of that line, it's commented out (and thus mysql is disabled). remove the semicolon, save, and restart apache to enable it.


Also - depending on how you installed things - you should check to make sure that you're editing the correct version of php.ini. Some LAMP packages, if I remember correctly, create new directories with their own versions of the ini and conf files and then redirect the system to use them. The files in /etc are never called, so editing them will have no effect whatsoever.


Note that mysql_connect is deprecated starting sometime in php 5. See the mysql_connect function and choosing an API from the PHP manual.

Nov 28, 2012 4:49 AM in response to pvasireddy

pvasireddy wrote:


I am a newbie to LAMP stack. I beleive I have setup apache,php and mysql correctly.


Modified php.ini to include mysql.default_socket = /tmp/mysql.sock

Those internet instructions are for Linux.


To setup MySQL on a Mac, see this user tip: https://discussions.apple.com/docs/DOC-3082

To setup a local web server, see this tip: https://discussions.apple.com/docs/DOC-3083

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Fatal error: Call to undefined function mysql_connect() in /Users/praveenvasireddy/localhost/test/test2.php on line 2

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.