Friday

How to connect MYSQL with PHP

 
            Mysql is back-end software which is used to store several data . Once the connection is made
between Mysql and PHP you can store and access data in mysql from the front end(browser).

 Let us see the php code to connect with your database .


<?php
$con=mysql_connect("localhost","Username ","Passwrd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$dbs = mysql_select_db("database_name");
?>
    Username - root       (If you are running in localhost) .
    Password - Your own mysql password .

$dbs = mysql_select_db("database_name");
  The above line is used to select the database ,so that you can access the data in it ..


                *****    Like us in FB & get updates ...... LIKE      *****


Mysql Commands in PHP

   $sql=mysql_query("select * from data where id='$id'");
  This Command is used to select "id" field from  "data" table .        

Command to Create table :                            
           
 create table ur_tablename(id varchar(10),name varchar(20));
Command to Insert data in table:
                 
            $sql=mysql_query("insert into ur_tablename(id,name) values(3,"pradeesh");
Command to Update data in the table:

                $sql=mysql_query("Update ur_tablename set  name='$name' where id='$id'");


          ******         Like us in FB & get updates ...... LIKE          ******


________________________________________________________________________

0 comments:

Post a Comment