Sunday, April 29, 2012

Web development: HTML, PHP, and SQL


First thing’s first, lets set up our environment. My IDE of choice is Netbeans, but that’s of little consequence. Next, install your PHP stuff. Later down the road, when we use MySQL, these tools will make yourlife a lot easier. In your php.ini file uncomment - extension=php_curl.dll to activate curl.

This post will tell you how to set upyour project. The easiest thing to start with is how to scrape a feed, basically cut and paste, see here. Quick posts to brush on your PHP:






Now let’s tap into Google APIs. Sign up for your Google License Key. Read how to use the Google API here and here. The Google News API is similar.

Next API were going to use is Twitter, well technically 3 Twitter APIs. The first is to get trending topics, seehere. Next, twitter searches, similar to Google’s search API, but you don’t need a key, see here. The third is a bit trickier, see here for help. Basically download Abraham's TwitterOAuth library add it to your project and go to http://dev.twitter.com/apps, register your app and get your keys.

Now before we jump in and start using SQL, I feel it’s important that you keep in mind the scope of your project. If you simply want to store a small amount of information with no respect to order, you might consider plain text. There’s a certain cost to setting up and maintaining a database and it may even hurt performance if you are just doing a simple project.

OK, ready? Start your server. Open up MySQL Query Browser. Right click on a Schema, create a new one or use a default, and create a new table. Now, let’s connect our new table to our PHP, see here. We’ve been getting json objects for our searches, so let’s store those in the database. For help see here, here, and here. I managed to get away with just using serialize() and mysql_real_escape_string() but not addslashes().

And there you have it. You are now the proud creator of a web application.

No comments:

Post a Comment