Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   connection String Php with Mysql..? (http://www.go4expert.com/forums/connection-string-php-mysql-t26828/)

tripathi123 1Oct2011 15:45

connection String Php with Mysql..?
 
help me ....

shabbir 2Oct2011 09:54

Re: connection String Php with Mysql..?
 
What kind of help?

pein87 11Oct2011 02:57

Re: connection String Php with Mysql..?
 
Php doesn't use connection strings like ASP.NET does. Instead you need to use two functions to establish a connection to both the database and the table.

PHP Code:

$C mysql_connect("localhost","username","password"); 

The arguments to the function are the host,username, and password.

You can check if there is a connection like so

PHP Code:

if($C)
{

echo 
"connection made";

}
else
{

echo 
"no connection";



PHP Code:

$DB mysql_select_db("database",$C); 

this function takes the database name and the connection resource(i.e the variable used for the connection function). However by default it uses the last connection resource if available.

As with the connection function you can use an if statement to check if the variable has any value.

PHP Code:

if($DB)
{

echo 
"database selected";

}
else
{

echo 
"database not selected";



From here you can use mysql_query() to send queries to the database and use the many return function to retrieve some data back from the database for displaying.


All times are GMT +5.5. The time now is 21:23.