inserting data into tables using sql command
inserting-data-into-tables-using-sql-command.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>inserting data into tables using sql command</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="inserting data into tables using sql command">
<meta name="keywords" content="php, example, code, table, sql command, sql, insert data into table">
<meta name="description" content="inserting data into tables using sql command">
<style>
h2, h4{background:#eee; color:#000084;}
h2{ padding:3px; margin:3px; font-size:22px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#0099FF;}
body{ background:#FFFFFA;}
</style>
</head>
<body>
<h2>inserting data into tables using sql command</h2>
<pre>
<?php
/*
---------------------------------------------------------------------
WE WANT TO INSERT DATA INTO A TABLE departments BY USING SQL COMMAND
---------------------------------------------------------------------
*/
$sql = "
INSERT INTO departments
(DepartmentID, DepartmentName, ManagerID, LocationID)
VALUES
(1, 'Information Technology', 1, 1)
";
/*
------------------------------------------------
YOU CAN INSERT MULTIPLE ROWS IN A SINGLE QUERY
------------------------------------------------
*/
$sql = "
INSERT INTO departments
(DepartmentID, DepartmentName, ManagerID, LocationID)
VALUES
(1, 'Information Technology', 1, 1),
(2, 'Accounting', 2, 1),
(3, 'Admin', 5, 1),
(4, 'Dinning', 4, 1),
(5, 'Marketing', 3, 1)
";
/*
----------------------------------------------------
IN PHP YOU CAN ALSO DO THIS.
GET CONNECTION TO DATABASE BY USING : mysql_connect()
SELECT DATABASE BY USING : mysql_select_db()
THEN RUN THE QUERY
----------------------------------------------------
*/
mysql_connect('localhost', 'root', 'root');
mysql_select_db('hr');
mysql_query($sql);
/*
-----------------------------------------------------------------------------
TO RUN THE PHP CODE PROVIDE REAL DATA TO mysql_connect AND mysql_select_db()
-----------------------------------------------------------------------------
*/
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..