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. :D
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.
Re: Official Learn PHP/MySQL Thread
Part 2: PHP Basics - Writing Scripts, Viewing Scripts, and Storing/Retrieving Variables
This part will deal with the basics of PHP. In this lesson, you will learn how to write PHP scripts, view them on the server, store variables, and retrieve variables.
First, let's talk about what exactly PHP is. PHP is a server-side scripting language. It stands for PHP Hypertext Preprocessor (yes, it's a recursive acronym). The concept behind PHP is very simple. First, the script is written and a .php extension is added to the file. Then, when a client requests the file, the server recognizes the extension of the requested file. The file is then interpreted by the server, then output to the client. This means that the code contained in a PHP file is essentially "compiled" before it is output to the client, and the code is not viewable. However, the server does not do this to all the text in the PHP file. Instead, it only interprets the text that is surrounded by PHP tags. Therefore, it is possible to insert PHP code anywhere in the page. As long as the text is surrounded by PHP tags then it will be interpreted by the server.
PHP tags look like the following:
Before we start, let's cover the basics of variables and output in PHP. If you have experience with other programming languages such as C, C++, C#, etc., you know that when you declare variables you need to declare a variable type. Well, you will be delighted to know that while PHP has this ability, it is not necessary. PHP determines the optimal variable type based on the data being passed to the variable.
I will cover more on variable types, changing variable types, operators, and control structures in the next lesson. For now, let's look at how we declare variables and retrieve variables. After that, we will create a script, upload it to the server, and view the output.
All variables in PHP are preceded by the $ sign. PHP variable names may only consist of numbers, letters, and underscore characters (A-Z,a-z,0-9,_). Underscores and capitalization may be used to make variables with multiple words easier to read (ie newVariable, new_variable). The following code declares multiple variables.
Now let's create our first PHP script. First, load WampServer and make sure the icon in the system tray is white, indicating all processes are loaded. Open Notepad++ and type the following into the text editor.
Now, left-click on the Wamp icon and select the localhost option. This will open a browser showing you your local server. Now, click the address bar and type lesson2.php at the end of the URL and press Enter (the URL should be http://localhost/lesson2.php).
The following should appear:
NOTE: I have attached the .php file so you can see it.
Re: Official Learn PHP/MySQL Thread
Part 3 - Variable Types and Operators
First off, I'd like to apologize for having been away from this tutorial for so long. I know a lot of people out there would like to learn PHP and have been talking about the thread, so sorry for the delay. This lesson will consist of mostly just information regarding variable types, getting/changing the variable type, and operators.
Let's start with variable types. For those out there accustomed to other languages (C/C++, C#, etc.) this will be mostly review. The following is a list of variable types in PHP:
Now, for the regular programmers out there, you are probably used to declaring the variable type before setting the values. PHP is much easier and tries to guess the variable type you want. Many times PHP is correct, however sometimes it is useful to declare variables before using them. PHP does allow type casting. To do so, just place the type you want the variable to be in parentheses before you set the value. Below are some examples.
These are the operators. If you don't understand their usage at the moment, we will cover them. Well that concludes this lesson. I know that I have not really explained arrays very well. Arrays are a very important variable type and are capable of storing almost everything you could ever need in a very simple and logical form.
Next lecture will cover arrays. After that, I will go over IF statements, FOR and WHILE loops, and how to create your own functions in PHP. Hopefully the next lecture won't be 15 months away :lol:
|All times are GMT -5. The time now is 12:01 PM.|
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2014, nV News.