Page 1 of 1

How to access MySQL database in PHP?

Posted: Mon Apr 17, 2006 6:47 am
by hanxiao
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I was trying to make a trial in Dreamweaver MX 2004 to access the database in MySQL 5.0 under Windows XP. 


I used the code from http://www.php.net like:

Code: Select all

<?php
	$link = mysql_connect('localhost', 'root', '12345678');
	if (!$link) 
                {
	   die('Could not connect: ' . mysql_error());
	}
	echo 'Connected successfully';
	mysql_close($link);
?>

But gives me a error says:"Fatal error: Call to undefined function mysql_connect() in D:\Apache Group\Apache2\htdocs\Learn\Welcome.php on line 10", which is saying the line with "$link = mysql_connect('localhost', 'root', '12345678');" something is wrong.

Because in my previous post, I got problem with setting up MySQL connection in Dreamweaver MX 2004, so I just want to have a try to see if PHP can connect to MySQL directly. It seems it doesn't work. Anyone has any idea about this?

Thank you.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Apr 17, 2006 7:13 am
by timvw
As long as you don't configure your php.ini in order to load the extension the function will not exist.
It's all mentionned in the INSTALL.TXT file and in the fine manual...

Have you searched the web for 'mysql_connect function does not exist'?

Posted: Mon Apr 17, 2006 8:16 am
by hanxiao
Thanks for your reply.

So now I know I need to modify the php.ini file again for extension.

I just uncommented the extension part for mysql. "extension=php_mysql.dll".

But it still gives me the same error message at the same line. Any idea?

Thank you.

Posted: Mon Apr 17, 2006 8:25 am
by feyd
Did you restart Apache?

Posted: Mon Apr 17, 2006 8:52 am
by hanxiao
Sorry about that code thing for my post. I am new here and new for php, mysql, apache etc.


I think I found the problems. But I am not sure which one is the vital one.

I did some changes in the setting files:
In httpd.conf, I added this line, which was in the php.ini file, which I followed the instruction on http://www.php.net, maybe it's my misunderstanding from the instruction, but I think it is really misleading me to do the wrong thing:
PHPIniDir "D:/PHP/php-5.1.2-Win32"

In php.ini, I added one more line for the extension, which was not in the recommended php.ini file.
extension=php_mysqli.dll

I also replaced the libmysql.dll file which was contained within the zip file of 5.0.18 version PHP from the http://www.php.net with the new file from http://dev.mysql.com/downloads/connector/php/
They have different size, so I am confused is it a mistake from php or it is just because mysql updated the dll file?

But everything is working, thank you.

If anyone has similiar problem with setting up extensions etc. can go to read this thread: http://forums.mysql.com/read.php?52,698 ... #msg-69846
It's really useful.

Posted: Mon Apr 17, 2006 8:54 am
by feyd
Do not cross post. Choose a thread and stay there.