Home Tutorial Php Sql Php Sql Variable

 
 

Php Sql Variable
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to create the variable in php for sql operation.

Php Sql Variable

This example illustrates how to create the variable in php for sql operation.

In this example we create a variable $con for mysql connection and $update for query. The sign ($) is used to create the variable in php.

 

Table: emp_table before insertion

 

Table: emp_table after insertion

 

Source Code of sql_variable.php

<?php
  // variable con created..
  $con = mysql_connect("localhost","root","root");
  if (!$con){
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);

  // variable update created..
  $update = "UPDATE emp_table SET emp_name = 'sandeep' WHERE emp_id = 1";

  mysql_query($update, $con);

  echo "Column <b>emp_name</b> updated successfully<br><br>";

  mysql_close($con);
?>

Download Source Code

 

Output:

Advertisement

Related Tags for Php Sql Variable:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com