php and database

hardik soni's Avatar, Join Date: Jun 2010
Contributor
Hello everyone,

I am new in PHP. I want to know how to establish connection between PHP and any database, Please guide me if you can...

In Anticipation....
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
http://lmgtfy.com/?q=connect+mysql+PHp
0
hardik soni's Avatar, Join Date: Jun 2010
Contributor
All right nice info from that site
but can anybody let me know something in your own language for the same topic ?

Thanks.
0
johnny.dacu's Avatar, Join Date: Jul 2010
Contributor
well... is simple. to estabish a mysql connection use:
PHP Code:
mysql_connect("server","username","password"
to select a database:
PHP Code:
mysql_select_db("db_name"); 
to perform a mysql query:
PHP Code:
mysql_query("query string"); 
0
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
First you need to make a database from your admin panel. (hope you know to do that)

Then the following script would give the basic concept of connecting:

PHP Code:
<?php

$username 
"your_db_username";
$password "your_db_password";
$database "your_database_name";
$host "your_host_address";

$db_handle mysql_connect($host$username$password);
$db_found mysql_select_db($database$db_handle);

if(
$db_found){
     print 
"Auuraah You sucessfully connected!";
     
mysql_close($db_handle);
}else{
     print 
"ahh Try Again!!";
}
?>
shabbir like this