Switch from ASP to PHP

July 1, 2007 at 12:57 am Leave a comment

   We’re going to switch from asp (with MS Access databases) to php (with a mySQL database) as quick as possible in this tutorial. We assume that you want to convert an existing asp site to php. You can find a great PHP tutorial on http://www.w3schools.com/php/default.asp. It’s all I read so far about PHP, so that should make you feel comfortable with me as your tutor :p. This file ain’t a full blown PHP tutorial, it just focusses on the important differences between ASP and PHP that might get you stuck for a while. A very sweet PHP host (free) is freehostia.com, so head your browser over there if you haven’t found one already.
1. Converting the MS Access database to a mySQL database
Open your database in MS Access, right-click on a table and select “export”. In the “save as” combobox you select the option with *.csv files. Click through the next steps with the default options: your table gets exported in a plain text file. Login on your php server, and launch phpMyAdmin. In your empty database, you create a table (enter the apropriate number of fields, this is the number of columns of your Access table). Now you have to create all the fields. Give them the same name as the column headers in your Access table (just because it’s easier) and select the apropriate type.When all the fields are created select “import”. Navigate to the text file that contains your exported table andselect the file. Check the option “CSV ~ ” and hit the button. Your records are imported! Repeat these steps for all the tables in your database. Hints (aka mistakes I made :p):
  • TINYINT cannot contain ints larger than 128! So don’t use it as an index or something like that, or your import will only add the first 128 records to your table!
  • If you had an auto-increasing field in your Access table, you select “auto-increment” in the “extra” combobox while entering the fields of your table. The field has to be unique for this to work (click on the key button of the field).
Right on! We converted our database so that we can connect to it from within PHP! But let’s learn some quick bits of PHP first..
2. Switching from ASP to PHP
What I’m going to do here is type some typical often-used ASP code and give you the PHP equivalent of it.
ASP Code PHP Equivalent
  echo “that chicken gave me a bad coupon”; ?>

So PHP is entered between . You use “echo” to write stuff to the output. Don’t forget the semicolon at the end!

ASP Code PHP Equivalent
  $item=”coupon”; echo “that chicken gave me a bad ” . $item; ?>

Variable names always start with a dollar sign. Instead of the ampersand you use a dot. I know, it’s weird.

ASP Code PHP Equivalent
  //php is cooler!  $artist=”kyuss”; if ($artist==”kyuss”) {      

echo “AAAA Yeah!”;

} else {

echo “OOOO No!”;

} ?>

The if-construction follows the C variant with { and } instead of else and end if. Don’t forget the parentheses around the condition. And an easy-to-make-mistake: you compare with == instead of with =. If you typed if ($artist=”kyuss”) { //don’t try this at home, kids.. PHP would assign “kyuss” to $artist, convert that to a boolean and check if that is true! The while and switch construction also follow a C- like syntax. Check it all out athttp://www.w3schools.com/php/default.asp! Now let”s see how we read form and url elements:

ASP Code PHP Equivalent
var1 = request.querystring(“name”) var2 = request.form(“age”) $var1 = $_GET(“name”); $var2=$_POST(“age”);

Pretty much the same thing.. Your SQL commands should stay the same I guess, one thing that changes a bit is:

Access SQL Code mySQL Equivalent
SELECT top 3 * FROM tblfiles SELECT * FROM tblfiles LIMIT 3
Right, we can live with that. Oh, another thing: mySQL is case sensitive, so pay attention when SELECT-ing strings with comparisons..
That’s it for this jumpstart into the world of php. Godspeed my man, godspeed!  
Advertisements

Entry filed under: Uncategorized. Tags: , , , , .

Scope with PIC microcontroller and Matlab

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

Trackback this post  |  Subscribe to the comments via RSS Feed


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.

%d bloggers like this: