[SOLVED]php 5 database connection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

[SOLVED]php 5 database connection

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

:D
Last edited by pleigh on Thu Dec 01, 2005 12:22 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

as far as I can remember you have to uncomment php_mysql/mysqli.dll whichever you prefer in php.ini...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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)
Last edited by Jenk on Tue Nov 29, 2005 5:34 am, edited 1 time in total.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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..
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

not mysqli, just mysql.

You need to uncomment the following line (by removing the semi colon prefix) in your PHP.ini

Code: Select all

extension=php_mysql.dll
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

aren't there lines in php.ini like this :arrow:
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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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... :D ..thanks a lot guys...
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

OK then uncomment the mysql.dll one, and get off to mysqling :wink:
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

remove the semi-colon before that line, then restart your webserver application (e.g. Apache):)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

n00b Saibot wrote:OK then uncomment the mysql.dll one, and get off to mysqling :wink:
haha!!thanks guys...i will do it. :D
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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. :)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 ;)
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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:

Code: Select all

extension_dir = "c:\PHP\ext"
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.
Post Reply