Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fatal error: Call to undefined function: mysql_connect()

Status
Not open for further replies.

mwpc

Programmer
Apr 28, 2002
53
US
On this machine PHP is unable to connect to MySQL.

Debian linux kernel 2.2.19
PHP version 4.0.3pl1,
MySQL distribution 3.22.32 on port 3306.

the php string

$link = mysql_connect( "localhost", "user", "password" )

produces this error message

Fatal error: Call to undefined function: mysql_connect()

(user & password are correct)

Replacing localhost with the IP number produces the same error.

Perl connects perfectly to mysql with the DBI module:

DBI->connect

PHP works perfectly with other functions.

phpinfo shows this configure command:

../configure' '--prefix=/usr' '--with-apxs=/usr/bin/apxs' '--with-regex=system' '--with-config-file-path=/etc/php4/apache' '--enable-calendar' '--with-db' '--without-dom' '--enable-filepro' '--enable-ftp' '--with-gettext' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-trans-sid' '--disable-debug' '--disable-static' '--with-gd=shared' '--with-imap=shared' '--with-ldap=shared,/usr' '--with-mm' '--with-mhash=shared' '--with-mysql=shared,/usr' '--with-regex=system' '--with-pcre-regex=/usr' '--with-pgsql=shared,/usr' '--with-snmp=shared' '--enable-sockets' '--with-ttf' '--enable-freetype-4bit-antialias-hack' '--with-t1lib' '--with-xml=shared,/usr' '--with-yp' '--with-zlib'


these loaded modules:

mod_php4, mod_setenvif, mod_unique_id, mod_expires, mod_auth, mod_access, mod_rewrite, mod_alias, mod_userdir, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_status, mod_negotiation, mod_mime, mod_log_config, mod_macro, mod_perl, mod_so, http_core


Debian sometimes has some strange paths.

The /etc/my.cnf file shows

socket = /var/run/mysqld/mysqld.sock

This symbolic link has to be made after reboot, before mysql will work:

ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock


I plugged this socket value into /etc/php4/apache/php.ini:

; 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 = /var/run/mysqld/mysqld.sock

; 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 =


Rebooted (again), still get the Fatal error.


Does anybody have any ideas?

Thanks

Mike
 
It looks like PHP was compiled on your system to use the MySQL client libraries as shared libraries. Does the output of phpinfo() make any other mentions of MySQL?


One thing to try:
Look in php.ini for a line that reads something like ";extension=mysql.so" and uncomment it. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks for the input.

1. I modified php.ini, there was a line for msql, I modified it for mysql and uncommented it. Restarted apache, still the fatal error.

2. There is no other mention of mysql in the phpinfo.

3. There is a mysql.so on the machine, used by the perl DBD module

/usr/local/lib/site_perl/i386-linux/auto/DBD/mysql/mysql.so

but that is the only mysql.so that is there.

Do I need to find another module and install it?
 
I didn't do the install, my friend who did it passed away last year, I am not up to speed on php installation.

 
I had the exact same problem on RH 8.

The MySQL libraries for PHP were not installed.

I went to and searched for php-mysql. Pick the rpm for your dist and install. You should then be good to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top