Check Domain Name


MYSQL connectivity scripts using PHP

The following is the Sample PHP to MySQL Connectivity Script:


Database name : db1
Username : dbuser
Password : dbpwd

PHP Code


}

-----------CREATE TABLE-----------------

<?
$db="db1"; $userName="dbuser";
$password="dbpwd";
$hostName="localhost";
$c=mysql_connect($hostName,$userName,$password);
$stmt="create table testtable(name varchar(20))";
mysql_select_db($db);
if(mysql_query($stmt)) { echo"Table createdsuccessfully"; }else {echo"error"; }< BR> ?>


------------INSERT INTO TABLE-----------------
<? $db="db1";
$userName="dbuser";
$password="dbpwd";
$hostName="localhost";
$c=mysql_connect($hostName,$userName,$password);
$stmt="insert into testtable values ('value3')";
mysql_select_db($db); if(mysql_query($stmt)) { echo"Value insertedsuccessfully"; }else {echo"error"; }? >
?>
----------------SELECT FROM TABLE-----------------
< ?
$db="db1";
$userName="dbuser";
$password="dbpwd";
$hostName="localhost";
$c = mysql_connect($hostName,$userName,$password);< BR> $stmt="select *from testtable";< BR> mysql_select_db($db); if($result=mysql_query($stmt)) { while($row=mysql_fetch_object($result)) { echo "
"; echo $row->name; } } else {echo "error"; } < BR> ?>

 

Visit Indian SEO for Search Engine Optimization Website
Maintenance Services Bangalore India
Visit indianattire.com for Indian attire
Copy Right 2001 - 2005 All Rights Reserved Terms and Conditions