Jump to content

Archived

This topic is now archived and is closed to further replies.

141stagecoach

Undefined function: mysql_connect()

Recommended Posts

I'm trying to learn PHP and ran several simple tests that confirmed that PHP was working, but when I attempted to connect to a MySQL database, I got the following error message:

Fatal error: Call to undefined function: mysql_connect()

What would cause PHP to consider the mysql_connect() function to be undefined?

code:
$server = mysql_connect($host, $username, $password) or die(mysql_error());

Share this post


Link to post
Share on other sites
It means that your version of PHP doesn't have MySQL support.

Share this post


Link to post
Share on other sites
[!--quoteo(post=337571:date=Jan 17 2006, 09:37 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 17 2006, 09:37 PM) [snapback]337571[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It means that your version of PHP doesn't have MySQL support.
[/quote]

Thank you for your help, fenway.

MySQL version is 5.0
PHP Version 4.2.2

I believe my version of PHP [u]does[/u] have MySQL support.
phpinfo() returns:

------Configure Command-------
--with-mysql=shared

----------dbx-----------
dbx support enabled
dbx version 1.0.0
supported databases
MySQL
ODBC
PostgreSQL
Microsoft SQL Server
FrontBase
Oracle 8 (not really)
Sybase-CT

... and from /etc/php.ini :
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo cfg_get_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =

===========================
Does any of this give you a clue?
===========================

Share this post


Link to post
Share on other sites
Yes it does. Your version of PHP has MySQL support built-in as a module (hence the "shared"), but you still need to tell php to _use_ it. Make sure there is an "extension=mysql.so" in the appropriate section of your php.ini file. BTW, I believe you'll need to use the mysqli libraries for MySQL 5.

Hope that helps.

Share this post


Link to post
Share on other sites
[!--quoteo(post=337557:date=Jan 17 2006, 10:23 PM:name=doublew)--][div class=\'quotetop\']QUOTE(doublew @ Jan 17 2006, 10:23 PM) [snapback]337557[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm trying to learn PHP and ran several simple tests that confirmed that PHP was working, but when I attempted to connect to a MySQL database, I got the following error message:

Fatal error: Call to undefined function: mysql_connect()

What would cause PHP to consider the mysql_connect() function to be undefined?

code:
$server = mysql_connect($host, $username, $password) or die(mysql_error());
[/quote]


you need to use mysqli_connect with mySQL 5.+

[a href=\"http://ca3.php.net/manual/en/function.mysqli-connect.php\" target=\"_blank\"]http://ca3.php.net/manual/en/function.mysqli-connect.php[/a]

Share this post


Link to post
Share on other sites
[!--quoteo(post=337873:date=Jan 18 2006, 09:54 PM:name=phptryhard)--][div class=\'quotetop\']QUOTE(phptryhard @ Jan 18 2006, 09:54 PM) [snapback]337873[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you need to use mysqli_connect with mySQL 5.+

[a href=\"http://ca3.php.net/manual/en/function.mysqli-connect.php\" target=\"_blank\"]http://ca3.php.net/manual/en/function.mysqli-connect.php[/a]
[/quote]

I have been looking and searching for two days to get this figured out.

Everyone says the same thing, add the php path to the system variables, move the libmysql.dll, move php5isapi.dll Nothing is working.

I am at a complete stand still on this web app until I can get this figured out.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
I don't think we can help anymore -- we've pointed you to the correct resources, and you're simply going to have to work through installing the mysqli libraries and correctly configuring it to work with MySQL and apache. Good luck -- feel free to post specific issues that you run into during this process.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.