Page 1 of 1

DB Connection

Posted: Sat Jan 02, 2010 3:31 am
by jotnarta
Hi All
I am a new bie to PHP, I am trying to connect to mysql db, but it doesn't work :banghead: , would u please tell me in steps how to connect to mysql db.

I have MySql 5, and PHP 5.

Thank you

Re: DB Connection

Posted: Sat Jan 02, 2010 4:56 am
by prayathana
Its simple just use
<?php
$con = mysql_connect("localhost","username","password");
if(!empty($con)){
mysql_select_db("databasename");
}

?>

Thatz it

Re: DB Connection

Posted: Sat Jan 02, 2010 5:26 am
by jotnarta
Thank you buddy, but I don't think it's the problem, I think that I have a problem in configuring php with mysql.

I defined "extension_dir" in php.ini, and I put the location of ext folder in the path, but it's not work :( , could you
help me with this?

thank you

Re: DB Connection

Posted: Sun Jan 03, 2010 5:18 am
by jotnarta
Do I have to do more configuratioins???

Re: DB Connection

Posted: Sun Jan 03, 2010 5:22 am
by jotnarta
When I run the web page, I get this message "The web page has a programming error" !!!!!!

Re: DB Connection

Posted: Sun Jan 03, 2010 6:34 pm
by califdon
I'm afraid you have asked an open-end question. Assuming that you have already established that your web server is working and able to parse PHP, and that your MySQL is running (do you know if it is?), then a lot depends on what OS you are using. If this is Windows, you can check Services, if it is LInux, you can do something similar. Then you must be using the correct port number. You have taken care of one configuration statement, but there are others in the PHP config and the web server config. When you get an error like you say you received, you have to determine what the error means. Nobody can tell you what "the web page has a programming error" means. You have to use some debugging techniques to find out WHICH part of the web page has the error, then exactly WHAT that error is! Where is that error message coming from? It doesn't look familiar to me. If you post code here in the forum, please be sure to enclose the code in [syntax=php]and[/syntax] tags, to highlight the code syntax.