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()

The 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.

On another forum, this suggestion was made:

"One thing to try:
Look in php.ini for a line that reads something like ";extension=mysql.so"
and uncomment it. "

I did it, still no joy.

I suspect that the mysql.so lib is not available to PHP, but I am not up to
speed on PHP installation. My friend who did the install is unavailable.

Is this like a Perl lib:

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

Can the mysql.so be installed in a lib directory somewhere, or does
apache/PHP need to be recompiled with the module present?

Does anybody have any ideas?

Thanks

    • [deleted]

    The cause of the error is simple: the PHP version that you are running does not have mysql support.

    Your phpinfo shows you built mysql support as a shared object, is that '.so' file available where the .configure command looks for it?

      Hi Vincente, thanks for the feedback.

      Which .configure command are you talking about?

      I have 1 version of mysql.so, located in

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

      where the Perl DBD module finds it.

      If (1) this is the same module that can be used by PHP and (2) I can figure out where PHP is looking for it, no problem, I can copy it or sym link it.

      Thanks again

        • [deleted]

        .configure is the command you use to 'configure' your PHP sourcecode before you compile and install PHP.

        But from your reaction I gather that you did not build this version PHP yourself.

        And chance of letting a system adminstrator look at it for you?

          I'm having the same problem. PHP was installed as an RPM during installation of RedHat 8.0. Here is the configure command reported in phpinfo():

          './configure' '--host=i686-pc-linux-gnu' '--build=i686-pc-linux-gnu' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db3' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'

          Just like the original post, --with-mysql is pointing to shared,/usr. I have a mysql.so file at:

          /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/auto/DBD/mysql/mysql.so

          Since the install was done from an RPM, is there a way to find out where "shared" is pointing to? Would it be easier to recompile PHP?

          Thanks,
          SiaFhir

            Write a Reply...