If your interested in learning or playing with PHP. Here is a short introduction to get you started.I expect that you have some basic programming skills already. (or the willpower to stay and play for a while)
Download It
If your using a window OS you will want an"XAMP" installation. It installs Apache, PHP and MySQL on windows.Most of them are simple: download, unzip and click the "start"executable. I like to use Uniform Server. I won't go into debugging apache in this article, but I will suggest that you shut off any program that uses the web server ports. (Visual Studio, IIS, Skype).
Alternatively you can play on any website you have, most will have php enabled.
Basic Things to know
If statements
if( boolean )
{
//...some code
}
elseif( boolean )
{
//...some code
}
else
{
//...other code
}
Loops
for($i=0;$i<10;$i++)
{
//...code
}
while( boolean )
{
// ...code
}
Variables, Sessions and Forms
Normal Variable: $username;
Session Variable:$_SESSION["username"]
Form Post Variable: $_POST["username"]
Form Get Variable: $_GET["username"]
Kill a session variable:$_SESSION["username"] = "";
Database
PHP normally uses mySQL, but each of thefunctions below have an equivalent function for most database systems.
$db_host = "localhost";
$db_user = "user";
$database = "dbname";
$db_passwd = "pass";
mysql_connect($db_host, $db_user, $db_passwd);
$q = mysql_query("select * fromuser");
while($row = mysql_fetch_object($q))
{
print $row->username;
}
Alternativly you can usemysql_fetch_row($q)...this will get an array of the field values and you canaccess them by $row[0], $row[1]....etc.
As with most high level languages, php has anumber of functions available to it. You can search the very friendlydocumentation at www.php.net
Objects and Classes
Class DateUtils
{
function DateUtils()
{
//...constructor
}
function getToday($format)
{
return date($format);
}
}
And here is how to use the class
$util = new DateUtils();
print $utils->getToday();
What else would you like to know?