Databases| SQL| MySQL| Questions? | Software Development
 

PHP SQL Insertion

                         

PHP SQL Insertion is used to execute MySQL queries in PHP script. It is used to send insert query or command that adds the records to MySQL.

Understand with Example

The Tutorial illustrate an example from 'PHP SQL Insertion'. To understand and grasp the example we create a table 'Stu' that create the required fields and datatypes respectively. The Table 'stu' has a Primary Key ID.

Create Table Stu:

CREATE TABLE `stu` (                     
          `id` int(11) NOT NULL auto_increment,  
          `name` varbinary(10) default NULL,     
          `class` int(11) default '12',          
          PRIMARY KEY  (`id`)                    
        )

phpsqlinsertion.php:

The PHP SQL insertion is saved with .php extension. The server side scripting include a local host, user, password and name of the database to which records are added. To execute the queries, the connection would be built between the front-end and MySQL in the backend. Once your connection is built successfully, you can add the records to the database. The die function( ) illustrate  that connection could not established and exists from the current script.

<?php
	$host = "localhost";
	$user = "root";
	$password = "root";
	$database = "komal";
	$connection = mysql_connect($host,$user,$password) 
		or die("Could not connect: ".mysql_error());
	mysql_select_db($database,$connection) 
		or die("Error in selecting the database:".mysql_error());
	$sql="insert into stu(name,class) values('komal',12)";
	echo "Insertion Successful ...";
	
	echo "</table>";
	mysql_close($connection);
?>

Output

Insertion Successful ...

                         

» View all related tutorials
Related Tags: php sql mysql c query table delete io sed tab if condition ie record where records to base ci e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map | Privacy Policy

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.