PHP Programming 101

January 22nd, 2015

PHP to Get it’s own Stack

Posted by Conrad in Information

zendPHP is the most popular programming platform to ever grace the web and thanks to PHP, most of today’s web sites, blogs and many other internet staples are made possible with the use of PHP. Now one of the best news to come out of the PHP world is the announcement of the development of the Zend Server which would allow web application deployment and monitoring easy. This has been the most welcome news for till this, most systems have had to rely on the long used LAMP standard that worked but still relied on more traditional development methods that were labor intensive and quite hard to troubleshoot.
Zend promises to deliver faster development, deployment and bug fixing capabilities we can only dream of. (more…)

January 15th, 2015

Working with variables: isset(), empty(), and unset()

Posted by Conrad in Basic Programming, PHP


bool isset ( mixed var [, mixed var [, mixed ...]])
void unset ( mixed var [, mixed var [, mixed ...]])
bool empty ( mixed var)

There are three very basic functions that help you use variables, and these are isset(), empty(), and unset(). Isset() and empty() are almost opposites, but not quite – isset() will return true if a variable, passed in as its only parameter, has been set in the script already, whereas empty(), which also takes a variable as its sole parameter, will return true if the variable has a false value. This is not the same thing!

To illustrate the difference consider the variable $foo being set to false – isset() would return true because $foo is a variable that has a value, and empty() would also return true because $foo’s value is false. To check for “variable not set”, use the not operator !, as in “if (!isset($foo)”.

Unset() removes an existing variable entirely, so that isset() will return false. That variable can be recreated later on in the script, however. Use unset() when you want to delete a variable.

Source

January 8th, 2015

Understanding Cookies

Posted by Edi in Information

Photobucket

What exactly is a cookie? It’s not a food, in the computer world, a cookie is a small amount of information sent by a Web server to a web browser. They are sent back unchanged by the browser each time it accesses that server. They are used for tracking, storing, authenticating information regarding the users which include sites visited. They give capabilities that make the web easier to navigate. If you are using Microsoft’s Internet Explorer to browse, you can see all of the cookies that are stored on your machine. They are usually stored in a directory called c:\windows\cookies.

It is composed of a cookie name and cookie value. The setcookie function() can be used to send a cookie to a browser to request your PHP page.

January 1st, 2015

More into the syntax of PHP

Posted by Conrad in Basic Programming, Sample Code

As you might have seen, all of the PHP statement ends with “;” which would be somewhat similar to Perl. The valid HTML code that was handed back to the server was :
Sample:
html>
head>
body>
Who are You?
br />
My name is MacGyver.
/body>
/html>
(Note: opening “<” were removed to allow display of the code)
More in the coming posts when we dig deeper as we widen our understanding of PHP.

December 25th, 2014

Php? How does it work?

Posted by Conrad in Information


Image Source:technical-itch.co.uk

What are the uses of Php in the whole computing thing? We might wonder. The answer is simple. Php is practically used everywhere. It is being adapted to multiple platforms. The scripting language has revolutionized the way we communicate within the internet. Php reads and writes files. It is used to execute basic directory and file monitoring and maintenance. Simply put, Php has enabled developers and programmers and users to do things that wasnt possible to do in the web the previous years, like editing specific documents and files remotely. It is used to search files. Collect them and for the information stored in that file to remain there and retrieve it when needed. Now, information is more accessible. It does not require to be coded to a certain database. It can generate HTML and PDF files. It can process XML for HTTP. Its amazing capability to function on different data source makes it the idela tool for search engines.

December 18th, 2014

PHP Scripts on the Web

Posted by Conrad in Basic Programming, Sample Code

PHP Scripts on the Web

There are a lot of PHP scripts you can check out on the web. Some PHP scripts can even be downloaded and used on your own websites. Most of these scripts can be customized accordingly, but just make sure you save it as another file since in the event you have errors, you may find yourself having to revert to the original file.

You will be surprised at the number of scripts you can find on the web. A lot of them are good and others really basic. But the thing to get out of them is really the script design structure to which will help you learn. After seeing all of these, you will surely get yourself to write you very first PHP script to display on the Internet.

December 11th, 2014

PHP BASIC CODING

Here are some of the basic things to be in mind while coding your dynamic web pages using PHP.

I. PHP basic syntax

PHP is a script that is place inside a HTML document that’s why you need to put the basic codes of HTML such as and .
PHP is open with the (?)question mark followed by “PHP” and closed with a (?) question mark.

II. Displaying in PHP

In order to display a text in PHP you need to use the keyword ECHO or PRINT. all code line ends with a semicolon.

To be continued…

firefoxss23hqcom.jpg

image source: www.23hq.com

December 4th, 2014

PHP Basics

Posted by Conrad in Basic Programming, Sample Code

Now that you have installed the necessary web server software and tested that it works (which is included in the manual) we can now get to know the basics of PHP. For our guide we will be using HTTP combined with PHP, this allows PHP code to be embedded into regular html pages and thus simplifying the execution by simply requesting the page. PHP uses start and stop tags in the form of “?php” and “?” and below is a sample:

".. PHP Code".
?>

The following sample has PHP code embedded within HTTP:



Fan: Who are You?

//print output
Echo "My name is MacGyver";?>

Upon execution or opening the page this would give you text in the browser stating the following words. “Who are You?” “My name is MacGyver“. This would be the equivalent hello world program many books use in teaching the basics of programming.

November 27th, 2014

How to Export Data From MySql to CSV

Posted by Edi in Codes, PHP

This is a simple code that exports mysql database data to csv (delimated) data.

//a small class for database connectivity
class database {
private $db_handle;
private $user_name;
private $password;
private $data_base;
private $host_name;
private $sql;
private $results;
function __construct($host = “localhost”, $user, $passwd) {
$this->db_handle = mysql_connect($host, $user, $passwd);
}
function dbSelect($db) {
$this->data_base = $db;
if (!mysql_select_db($this->data_base, $this->db_handle)) {
error_log(mysql_error(), 3, “/phplog.err”);
die(”Error connecting to Database”);
}
}
function executeSql($sql_stmt) {
$this->sql = $sql_stmt;
$this->result = mysql_query($this->sql);
}
function returnResults() {
return $this->result;
}
}
//database variables
$host = “localhost”;
$user = “root”;
$passwd = “”;
$db = “bg_db”;
$sql = “SELECT * FROM table ORDER BY id”; // a query to fetch records from database
$dbObject = new database($host, $user, $passwd);
$dbObject->dbSelect($db);
$dbObject->executeSql($sql);
$res = $dbObject->returnResults(); // result reasource
$newFileName = “emp_names.csv”; //file name that you want to create
$fpWrite = fopen($newFileName, “w”); // open file as writable
$nameStr = “”;
$rows = mysql_fetch_assoc($res); // fetching associate records
$sStr = “”;
//first store the fields name as header of csv in $sStr
foreach($rows as $key=>$val) {
$sStr .= $key.”,”;
}
//then store all records
do {
$sStr .= “– —–\n”; //to seprate every record
foreach($rows as $key=>$row) {
$sStr .= $row.”,”;
}
}while($rows = mysql_fetch_assoc($res));
$sStrExp = explode(”– —–”, $sStr);//separate every record
foreach($sStrExp as $val) {
$sStr2 .= rtrim($val, “,”);
}
echo $sStr2;
fwrite($fpWrite, $sStr2); //now write to csv file
fclose($fpWrite);//close file
?>

November 20th, 2014

The Convenience of Ready-Made Scripts

Posted by Hannah in Codes

So you know the basics of PHP coding, and you’re really keen on trying out your new-found knowledge and skills; that’s all and good, but who said that you always have to build everything from scratch.

One of the best things about PHP is that its popularity means that there’s a plethora of ready-made scripts and programs that you can get on the Internet (both free and paid), which you can use for your particular need. Take the smart route when programming with PHP and save yourself the trouble of coding everything so that you can focus on problems and/or apps that really need to be coded from scratch.

Just make sure that the PHP scripts you get online have a license that will allow you to make modifications or can be embedded as part of your bigger code if you need to use it that way. A lot of PHP scripts like financial tools scripts are copyrighted so make sure you don’t get in trouble just for overlooking legalities.

Image via Eric Mueller

Next Page »