WebRef.eu  - Internet Marketing and Online Business Resources  

Home / Site Map | Blog | Contact

PHP Notes

Notes on the PHP programming language.

PDO

PHP Data Objects, or PDO, is a database abstraction layer specifically for PHP applications. PDO provides a consistent API for your PHP application regardless of the type of database server your application will connect to. In theory, if you are using the PDO API, you could switch the database server you used, from say Firebird to MySQL, and only need to make minor changes to your PHP code.

https://www.php.net/manual/en/mysqli.overview.php

Its main disadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server.

mysqli

The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later.

https://www.php.net/manual/en/mysqli.overview.php

 

Make a Form Post to Itself with PHP

Use $_SERVER["PHP_SELF"] (in conjunction with htmlspecialchars to avoid possible exploits). i.e.

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
...
</form>

See: https://stackoverflow.com/questions/5826784/how-do-i-make-a-php-form-that-submits-to-self

Count Array

The count function will count the number of items in an array. Example script:

<?php

$animals = array("Lion", "Tiger", "Wolf");

$arrLength = count($animals);

// 3 will be given
echo "The array length is " . $arrLength . "!<br /><br />";

// loop through the array, this will loop up to 2, giving the 0, 1 and 2 elements of the array, i.e. all of them
for($i = 0; $i < $arrLength; $i++) {
echo $animals[$i];
echo "<br />";
}

?>

View output of animals-array.php script

PHP explode() Function

https://www.php.net/manual/en/function.explode.php

Example:

// Example 1
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

View Server Info

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

PHP Function

The purpose of PHP functions is for you to stop having to write the same code again and again. Instead, you put it in a function and call the function each time.



Visit LowPrices.co.uk for Your UK Shopping



 




Low Prices UK Shopping

Compare Prices
at LowPrices.co.uk


Home / Site Map | Contact

All Content ©2020 WebRef.eu