Page 1 of 2
[SOLVED]php 5 database connection
Posted: Tue Nov 29, 2005 5:24 am
by pleigh
just now, i switched to php 5 from version 4...i believe that php 4 has a built-in mysql support...i was wondering how to add mysql support for php 5...i tried to connect to mysql database through this function
Code: Select all
$connect = mysql_connect("localhost", "root", "password") or
die ("Check your server connection");
and it prompts me this error
Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\myPHP\TMP1h1j2qr0ub.php on line 4
tried to change the function to mysqli_connect(), but still, the error appears...
any help from you guys is highly appreciated...thanks in advance..

Posted: Tue Nov 29, 2005 5:29 am
by n00b Saibot
as far as I can remember you have to uncomment php_mysql/mysqli.dll whichever you prefer in php.ini...
Posted: Tue Nov 29, 2005 5:34 am
by Jenk
and if on Windows, copy the libmysql.dll and php_mysql.dll files into the C:\Windows\System32 directory, it will not work if they are anywhere else.
(Apache/PHP won't start anyway, but this will be your next problem if you don't copy them :p)
Posted: Tue Nov 29, 2005 5:34 am
by pleigh
i tried to find the .dll file that you said but it is not in the .ini file...i also tried to find the mysqli keyword but i can't understand what it said..thanks for the reply noob..
Posted: Tue Nov 29, 2005 5:39 am
by Jenk
not mysqli, just mysql.
You need to uncomment the following line (by removing the semi colon prefix) in your PHP.ini
Posted: Tue Nov 29, 2005 5:41 am
by n00b Saibot
aren't there lines in php.ini like this
php.ini wrote:
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_msql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
Posted: Tue Nov 29, 2005 5:44 am
by Jenk
not in mine (though mine is a maintained old one, probably should get round to 'upgrading' it..)
unless you want to make use of the mysqli_* functions, there is no need to include the mysqli library extension.
Posted: Tue Nov 29, 2005 5:49 am
by pleigh
i'm afraid i don't have those lines...maybe because i used the microsoft installer provided, but ok, i'll try to download and install the zip file...maybe its there...and i'll get back here if i can't, again, configure it...

..thanks a lot guys...
Posted: Tue Nov 29, 2005 5:53 am
by pleigh
this is all the extensions in my .ini file
;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_msql.dll
;extension=php_mysql.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
i can't see any mysqli.ini there...
Posted: Tue Nov 29, 2005 5:57 am
by n00b Saibot
OK then uncomment the mysql.dll one, and get off to mysqling

Posted: Tue Nov 29, 2005 5:57 am
by Jenk
remove the semi-colon before that line, then restart your webserver application (e.g. Apache):)
Posted: Tue Nov 29, 2005 6:00 am
by pleigh
n00b Saibot wrote:OK then uncomment the mysql.dll one, and get off to mysqling

haha!!thanks guys...i will do it.

Posted: Wed Nov 30, 2005 3:48 am
by pleigh
hi, here i go again...i had a fresh format of my win xp...installed the latest XAMPP from apachefriends to get started with php 5 easily...i really thought it would be easier for me to connect to mysql database but the same problem above occur...question: should i copy some files from my php such as the libmysql.dll and so on to my c:\windows\system32 directory??
thanks again in advance.

Posted: Wed Nov 30, 2005 4:27 am
by n00b Saibot
pleigh wrote:question: should i copy some files from my php such as the libmysql.dll and so on to my c:\windows\system32 directory??
It is a much required step before you can start mysqling

Posted: Wed Nov 30, 2005 4:29 am
by Skittlewidth
Jenk wrote:and if on Windows, copy the libmysql.dll and php_mysql.dll files into the C:\Windows\System32 directory, it will not work if they are anywhere else.
Not so, you just need to make sure you've correctly set your extension_dir e.g:
I did this a few days ago after reformating my machine, following the recommended install instructions in the text file for the PHP5 binary.
Also changed Apache to load my ini file from the PHP folder which has made upgrading and maintanence so much easier now that everything is in one place. (I upgraded to 5.1.1 the following evening)
Only trouble I had was loading the mysql.dll funnily enough. Everytime I restarted apache2 it couldn't find the dll despite the path being correct.
After rebooting the computer it worked fine. I guess the dlls hadn't registered when I unzipped the PHP package or something. I never went near the System32 folder.