Page 1 of 1

MySQL connect

Posted: Sun Oct 23, 2005 12:05 am
by Zaid
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi friends, 

I am brand new to PHP and I am really just learning it having installed the compiler for it along with a command-line version of MySQL on my windows XP personal laptop.  

I have been trying to connect to this MySQL database but to no avail.  I am using the following line of code to connect:

Code: Select all

$dbcnx = mysql_connect('localhost', 'root', '111111');

echo "Database connection is the following: $dbcnx";

if ($dbcnx) 
{
   echo ("<P>Unable to connect to MySQL database server at this time.  Please modify code.<P>");
}


This results in the following error message:

Code: Select all

Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\ProcessForm.php on line 50
When I type 'help' in the MySQL command prompt, among other information, it gives me the following:

Code: Select all

c:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe
connection id: 6
current user: root@localhost
connection: localhost via TCP/IP
TCP Port: 3306
In my php test page, any echo statement that comes before the "mysql_connect" statement is outputted, any echo statement that comes after the "mysql_connect" statement seems to be ignored and is not printed onto the webpage.

Do I have to install any additional componenents to my PHP install (version 5)? Or modify the php.ini file? I would assume this should be quite simple but I haven't figured out anyway to officially connect.

Any help would be greatly appreciated.

Thanks in advance

Zaid


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Oct 23, 2005 12:12 am
by feyd
MySQL is not compiled into PHP anymore with version 5. If you installed PHP via the installer, you need to download the zip, extract out the files over your existing install and edit the php.ini making php_mysql.dll or php_mysqli.dll load. A snippet from one of my installations

Code: Select all

;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_netools.dll

edit: if you want to know more, enter "mysql_connect undefined" (minus the quotes) in the search page, make sure to select "Search for all terms"

Posted: Sun Oct 23, 2005 9:19 am
by Zaid
Thanks for the reply.

However, I got my hands on the

php_mysql.dll
php_mysqli.dll

files.

However I am getting the same

Code: Select all

Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\ProcessForm.php on line 50
error.

In the php.ini file the extension_dir is listed as the following:

Code: Select all

extension_dir = "./"
This would seem to mean that extension files should be in the root directory. Should they be in the same directory as the php.ini file (i.e., c:\windows) or in the php directory (i.e., c:\php)?

Furthermore, I have added the following in the in php.ini file, where it lists the dynamic extensions:

Code: Select all

;extension=php_msql.dll 
;extension=php_mssql.dll
I am simply not sure why this is not working and I have been doing a lot of reading and testing to no avail.

Again, any help would be greatly appreciated.

Thanks,
Zaid

Posted: Sun Oct 23, 2005 9:35 am
by feyd
A semicolon in a ini file is a comment, so remove the semicolons from those lines. Update the extension directory directive to the correct full path. Right now, it's referencing the current working directory, which is rarely where the extensions actually reside. You will probably need to copy libmysql.dll (I believe that's the name) into the path as well.

Posted: Sun Oct 23, 2005 1:19 pm
by John Cartwright
Make sure you restart apache too ;)

It worked

Posted: Mon Oct 24, 2005 6:14 pm
by Zaid
Thanks a lot guys!

It worked. The problems were just as you suggested Feyd:

- libmysql.dll had to be loaded into the path
- the path for extension_dir had to be changed
- semi-colons had to be removed from php.ini file

Awesome!

I really appreciate it

Have yourselves a great day gentlemen

Zaid