Database and SQL query in PHP and ASP.NET


After many many days, today early in the morning, I found some time to make a connection to a MySql Database and do some PHP.
It was a good experience all together. After all, now, for the time being, I’m busy doing some database operation in ASP.NET.
In the midst of ASP.NET, some PHP and MySql brings a fresh breeze.
Now for the people who want to do some database operation in PHP, I’d like to share my experience.
Besides, I’ll give an example of ASP.NET database operation so that readers can compare the pros and cons of two great dynamic web language.

First PHP. The code is very simple:

A MySql Database Connection Made

Database name is ‘produce’, table is ‘products’ which has three columns


$connection = mysql_connect("localhost", "root", "") or die("Could not connect");
$db = mysql_select_db("produce", $connection) or die("Could not select database");
$query = "SELECT * FROM products";
$result = mysql_query($query);

echo "

echo “

echo “


while ($row = mysql_fetch_array($result))

echo “

echo “


echo “

Product ID Product Name Product Number
“, $row[‘productID’], “ “, $row[‘productName’], “ “, $row[‘ProductNumber’], “




It looks like this:

I have made a database 'produce' through PHPMyAdmin, then made a table named 'products', after that I made three columns with 'productID' having primary key.

In ASP.NET, if I want to do the same thing, I don’t have write a single code! The fun of that web language lies there. There are so many options to connect to the Database, be it Oracle, MSSQL or anything else, and there is also so many options to operate that database through various data source controls, that in PHP the lazy programmers will definitely feel the heat! 🙂


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s