View Single Post
Old 07-29-08, 10:58 PM   #1
ViN86
 
Join Date: Mar 2004
Posts: 15,486
Default Official Learn PHP/MySQL Thread

Well, I would like to introduce everyone here to the wonderful world of PHP and MySQL. Since DOC and some others said they would like to learn about this very simple language, I would like to teach him and the others about it and how easy it is to use.

Let me first say that I am not an expert PHP programmer. However, I have written many web applications using PHP integrated with MySQL. I also have a good knowledge of the basics of the language. I will cover security (SQL injection, XSS, etc.) but again, I am not an expert. That being said, I am open to suggestions and new methods. So feel free to contribute freely to the separate feedback thread, and please do not threadcrap.

The Feedback thread is here: http://www.nvnews.net/vbulletin/showthread.php?t=117028

This will require some basic knowlege of programming. Preferrably, C/C++/C# programming background would be ideal, but minimal programming knowledge will work just fine.

So, consider today to be Part 1 of this educational series that has no defined number of parts.


Part 1: Installing and Using PHP/MySQL/PHPMyAdmin - The Easy Way

I currently use a local Apache/PHP/MySQL server to do all my development. I will introduce you all to a couple tools that I use for development.

First, I like to use a program called WAMP (Windows Apache MySQL PHP) for my development. I always work offline (as should you) to protect the code. I like using WAMP because it's very simple. They have new releases quite often and the releases always contain the most up-to-date versions available.

WAMP Server can be downloaded free from http://www.wampserver.com/en/ and is licensed under the GPL.

Once the program has been downloaded, install the program. All the default settings will be good for just starting. If you use Firefox, make sure you set Firefox as the default browser (it will notify you). Once the program has been installed, you can start the server by going to the Start Menu and selecting WampServer -> Start WampServer.

When it is loaded, you will see the following in your taskbar when you left-click on the icon. Right-clicking on the icon will bring up a menu to Exit the program.



This toolbar gives you access to all the required settings and everything else you may need for running/managing your local server. On the top are localhost and phpMyAdmin. The localhost option will open a browser/browser-tab and bring you to your local Apache server. The phpMyAdmin option will open your browser and bring you to the phpMyAdmin main menu. This program is a web-based application that allows you to easily (read: graphically) manipulate your MySQL database.

The www directory option will open up explorer and bring you to where your files are stored for the Apache server. This is where you will place your files to be hosted (ie .php, .html., etc.). The Apache/PHP/MySQL options below that are where you can enable/disable plugins and change settings for your server. Below that are the options to Start/Stop/Restart the services. NOTE: Apache and MySQL will run as services on your machine, and can be viewed in the Services window in Administrative Options in the Control Panel.

Finally, the Put Online option is to host the server live (online). This will accept incoming connection requests on port 80, assuming that your router is correctly configured and your ISP allows it. For now, keep this option unchecked, since you will be doing local development.

Ok, now that we have an Apache/PHP/MySQL server up and running, now we need something to write the PHP code. Preferrably, a program that has colorized fonts for functions/variables/reserved words/etc.

Personally, I prefer to use Notepad++. This program is labeled as Free Software (no licenses apply) and can be found at http://notepad-plus.sourceforge.net/uk/site.htm.

Notepad++ is a great text editor program. I set it to be the default .php file handler and you can do the same if you want. I do all my development in a text editor. I rarely use a WYSIWYG graphical editor (like Dreamweaver) so I won't really cover it here.

Now that you have your required tools installed, you are ready to begin writing PHP scripts. To test your install, left-click on the WampServer icon and your browser should open with a screen that looks like the following:



Well, that concludes this part. The next part will deal with the basics of PHP, including writing PHP scripts, adding them to your local Apache server, and some basics of PHP including variable declaration and retrieval, and how to output using PHP.
ViN86 is offline