Tuesday, January 20, 2009

What is PHP?

PHP, which stands for "Hypertext Preprocessor", is a server-side scripting language for creating dynamic Web pages. It is free and an open source and cross platform scripting language that runs on Windows or Linux/Unix. PHP's language syntax is similar to C's and Perl's. You don't have to declare variables before you use them and it is easy to create arrays and hashes. Much of its syntax is borrowed from C, Java and Perl with some unique features.

PHP provides excellent connectivity to several databases such as MySQL, Oracle, Sybase, PostgreSQL, and Generic ODBC. The most popular connectivity database compatibility that PHP used is the PHP/MYSQL.

PHP can also send HTTP headers, can set cookies, manage authentication, and redirect users. An HTML page that includes a PHP script will be determined through its suffixes or extension such as ".php" or ".php3”.

How to connect to Mysql Database using PHP

One of the best advantages of PHP is that, it can integrate with Mysql Databases and output those database records in your browser. Here's the basic script on how to connect to the Mysql Database.

//First you need to have a mysql username and password as the security access for your mysql database.

$username_conn = "dbuser"; //the mysql user with database rights
$password_conn = "dbpassword"; //the security mysql password
$hostname_conn = "localhost"; //the default is usually localhost
$database_conn = "task_db"; //the name of the database

//the script to connect to the database

$conn = mysql_connect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);


//select the database to work with
mysql_select_db($database_conn, $conn);
$query_rstTask = sprintf("SELECT taskid,taskname,assignedto FROM tbl_task");

//execute the SQL query and return records
$rstTask = mysql_query($query_rstTask, $conn) or die(mysql_error());

//fetch tha data from the database
while ($row = mysql_fetch_array($rstTask)) {
//Display the results
echo "Task ID:".$row{'taskid'}." Task Name:".$row{'taskname'}." Assigned To: ".$row{'assignedto'}."
";
}

//close the connection
mysql_close($conn);
?>

Sunday, January 18, 2009

Basics in PHP Programming

When doing php programming, it is a prerequisite also to know some basic in html programming. Learn the basic html tags such as table, form, div, img and etc. Then, once you have these basic knowledge already in html, it is time to learn php programming. PHP is a dynamic scripting language designed to develop dynamic web pages. Through php, you can integrate databases and embed to html output. You can program and perform loop tasks such as while loop, for loop, do while loop, if-else condition and etc. One tip to create website using php is to separate php scripts from the html tags.
you can start with php scripts then the html contents where to embed php scripts and functions. Just follow this basic format below.
start php tag
... set of php scripts and functions...
end php tag
start of html tag
.. set of html scripts and tags ...
end of html tag