PDA

View Full Version : php & mysql mysql_connect() error



davidh
05-06-2006, 12:07 AM
I'm running a basic script to connect to a mysql database in PHP. PHP works fine but if I try to connect to a mysql database
I get the error:

"Fatal error: Call to undefined function mysql_connect() in /home/david/public_html/php/do_mysql.php on line 9"
I installed php5-mysql
Googling around I got the suggestion that this may be because PHP was not compiled with mysql support built in. Can anyone confirm this?

markpreston
05-08-2006, 10:41 PM
Hi davidh,
It is certainly possible for this to be a reason for you to get the error you describe.
You can usually check the PHP configuration script using the phpinfo(); function.
This should give you output something like below (amongst other things):
Command '../configure' '--prefix=/usr' '--with-apxs=/usr/bin/apxs' '--with-config-file-path=/etc/php4/apache' '--enable-memory-limit' '--disable-debug' '--with-regex=php' '--disable-rpath' '--disable-static' '--with-pic' '--with-layout=GNU' '--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype' '--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro' '--enable-ftp' '--enable-dbase' '--with-gettext' '--enable-mbstring' '--with-pcre-regex' '--enable-shmop' '--enable-sockets' '--enable-wddx' '--enable-tokenizer' '--disable-xml' '--with-expat-dir=/usr' '--with-xmlrpc' '--enable-yp' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr' '--with-openssl=/usr' '--with-zip=/usr' '--enable-dbx' '--with-mime-magic=/usr/share/misc/file/magic.mime' '--with-exec-dir=/usr/lib/php4/libexec' '--without-mm' '--with-curl=shared,/usr' '--with-dom=shared,/usr' '--with-dom-xslt=shared,/usr' '--with-dom-exslt=shared,/usr' '--with-zlib-dir=/usr' '--with-gd=shared' '--enable-gd-native-ttf' '--with-jpeg-dir=shared,/usr' '--with-xpm-dir=shared,/usr/X11R6' '--with-png-dir=shared,/usr' '--with-freetype-dir=shared,/usr' '--with-mcrypt=shared,/usr' '--with-ming=shared,/usr' '--with-gmp=shared,/usr' '--with-imap=shared,/usr' '--with-imap-ssl' '--with-ldap=shared,/usr' '--with-mcal=shared,/usr' '--with-mhash=shared,/usr' '--with-mysql=shared,/usr' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--with-pgsql=shared,/usr' '--with-pspell=shared,/usr' '--with-unixODBC=shared,/usr' '--with-recode=shared,/usr' '--enable-xslt=shared' '--with-xslt-sablot=shared,/usr' '--with-snmp=shared' '--with-sybase-ct=shared,/usr' '--with-ttf=shared,/usr' '--with-t1lib=shared,/usr'

The bit you are interested in is the --with-mysql=...
If this isn't present then MySQL support is not compiled in.
With Knoppix PHP has MySQL support compiled in, but many Linux distros don't.
What Linux distro are you running?
Regards,
Mark Preston

Dominio
09-04-2006, 01:00 PM
I can second this problem. Amazing as it may sound, MySQL support does not seem to be compiled into the PHP configuration that comes with KNOPPIX 5.0.1 (the CD version). The phpinfo() function does not list the mysql module as installed.

Furthermore, I get strange problems with blank web pages being displayed when trying to start up the Apache2 webserver and surfing to http://localhost. I can't get the webserver to properly serve any HTML page that I place in /var/www (which is the DocumentRoot). A simple PHP file with a call to phpinfo() works, however. MIME/file type problem?

Getting PHP to work in KNOPPIX ought to not be harder than cleanly booting KNOPPIX, starting up MySQL, Apache, and then serving a PHP page with proper MySQL code in it. But this does not work in 5.0.1 (whereas it did in earlier versions, with one or two configuration tweaks), and for me that is a major grievance.

markpreston
09-04-2006, 11:17 PM
Hi Domino,
That is interesting. FWIW I am no longer using Knoppix for a hard disk installation, but I have moved on to a Kanotix derivative called Paipix.
See
http://aamorimsrv.fis.fc.ul.pt/tikiwiki/tiki-index.php?page=PaiPix_EN

This gives a working combination of PHP5, MySQL, PostgreSQL, Apache2, and Zope.

Regards,
Mark