Home Tutorial Php Sql Php Sql Script

 
 

Share on Google+Share on Google+
Php Sql Script
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to create the php sql script.

Php Sql Script

This example illustrates how to create the php sql script.

In this example we create a table "emp_counter" with three column that is id of integer type, name of varchar type , reset_counter of datetime type. We insert a values ('1', 'sandeep', 'SYSDATE()' ) in the table as below shown in the figure.

 

 

Table: emp_counter

 

Source Code of sql_script.php 

<?php
  $mysql_db = "test";
  $mysql_user = "root";
  $mysql_pass = "root";
  $con = mysql_connect("localhost", $mysql_user, $mysql_pass);
  mysql_select_db($mysql_db, $con);

  $drop_table = "DROP TABLE if exists emp_counter ";
  mysql_query($drop_table, $con);

  $create_query = "CREATE TABLE emp_counter (id INT NOT NULL AUTO_INCREMENT, 

   name VARCHAR(250), reset_counter DATETIME, PRIMARY KEY(id))";

  mysql_query($create_query, $con);
  print("Table Creation for <b>emp_counter</b> successful!<p>");

  $insert = "INSERT into emp_counter VALUES (1, 'sandeep', SYSDATE())";

  mysql_query($insert, $con);
  print("Inserted new counter successfully for this page");
?> 

Download Source Code

 

Output:

Advertisement

Related Tags for Php Sql Script:


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