Doing simple things to make great life

PHP with MSSQL Connectivity and Datamanipulation

Posted by kalaimaan on February 4, 2009

PHP with MSSql Connectivity and Datamanipulation

The following example is describe the details of insert delete and view the datas from my sql using PHP script

Note : Add line in PHP.ini



<table width=”50%” border=”2″>
<tr><td><center>Welcome to PHP script</center></td></tr>


$myServer = ‘localhost’;
$myUser = ‘sa’;
$myPass = “”;
$myDB = ’emp’;

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass);

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle) or die(“Couldn’t open database”);

//declare the SQL statement that will query the database
$query = ‘select * from empm’;


// insert details to the selected mysql table

// delete details to the selected mysql table

function printData()
//execute the SQL query and return records
$result = mssql_query(‘select * from empm’);

/*$numRows = mssql_num_rows($result);
echo “<h1>” . $numRows . ” Row” . ($numRows == 1 ? “” : “s”) . ” Returned </h1>”;

//display the results
while($row = mssql_fetch_array($result))
echo “<li>” . $row[’empid’] . $row[‘name’] . $row[‘pno’] . “</li>”;

echo “<br><table border=’1′ width=’50%’>”;
echo “<tr> <th>Id</th> <th>Name </th> <th>Phone No. </th> </tr>”;

while($row = mssql_fetch_array($result))
echo “<tr><td>” . $row[’empid’] . “</td><td>” . $row[‘name’] . “</td><td>” . $row[‘pno’] . “</td>” . “</tr>”;

echo “</table>”;

function insertData()
// Insert a row of information into the table “example”
mssql_query(“INSERT INTO empm (empid,name,pno) VALUES(‘0006′,’Sri’,’98418′ ) “);
echo “<br><b>Data Inserted!</b>”;

function deleteData()
mssql_query(“Delete from empm where empid =’0006′”);
echo “<br><b>Data Deleted!</b>”;





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: