Home | About Us | Services | Recent Work | Website Hosting | Contact Us | Tech-Support | Live Chat Support


MYSQL connectivity scripts using PHP

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>
            ?>
Copyright © 2005-2007. Indian SEO All rights reserved.