Php Sql Script


 

Php Sql Script

This example illustrates how to create the php sql script.

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:

Ads