DB Connection

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jotnarta
Forum Newbie
Posts: 4
Joined: Sat Jan 02, 2010 3:29 am

DB Connection

Post 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
prayathana
Forum Newbie
Posts: 1
Joined: Sat Jan 02, 2010 4:49 am

Re: DB Connection

Post by prayathana »

Its simple just use
<?php
$con = mysql_connect("localhost","username","password");
if(!empty($con)){
mysql_select_db("databasename");
}

?>

Thatz it
jotnarta
Forum Newbie
Posts: 4
Joined: Sat Jan 02, 2010 3:29 am

Re: DB Connection

Post 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
jotnarta
Forum Newbie
Posts: 4
Joined: Sat Jan 02, 2010 3:29 am

Re: DB Connection

Post by jotnarta »

Do I have to do more configuratioins???
jotnarta
Forum Newbie
Posts: 4
Joined: Sat Jan 02, 2010 3:29 am

Re: DB Connection

Post by jotnarta »

When I run the web page, I get this message "The web page has a programming error" !!!!!!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: DB Connection

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