From BC$ MobileTV Wiki
(Redirected from PDO)
Jump to: navigation, search

Php.png PHP stands for Hypertext PreProcessor, and according to[1] "is a server-side, widely-used, general-purpose scripting language that is especially suited for Web development and can be embedded into HTML."



Versions 1.x-3.x

Original versions of PHP were focused on speed of development through a powerful scripting language built for web first as an alternative to Perl/CGI.

Version 4.x

Greatly improved extension mechanism with PHP Extension Community Library (PECL).

Version 5.x

Introduced full OO concepts such as classes/polymorphism/inheritance to PHP for better code reuse. Deprecated the DB-specific PHP extensions, as it moved to PDO.

Version 6.x

Only available as an "alpha/PoC" fork then scrapped in favor of 7.x (never officially released). Composer came out as the leading PHP 5.x+ modular library dependency management solution during this time.

Version 7.x

Completely redefined DB-specific PHP extensions and removed them in favor of PDO.

[2] [3] [4] [5]

Version 8.x

[6] [7] [8] [9] [10] [11] [12] [13] [14] [15]




Using the following snippet, you can check the User-Agent and exclude Search Engines (other things you could do include, check for JavaScript/CSS/iFrame/Applet support, check):

if(isset($_SERVER['HTTP_USER_AGENT'])) {
   $agent = $_SERVER['HTTP_USER_AGENT'];
   $browser = get_browser($agent, true);
   if(!empty($browser['crawler']) || 
       strpos($agent, "robot")    ||
       strpos($agent, "bot")      ||
       strpos($agent, "spider")   ||
       strpos($agent, "crawl")    ||
       strpos($agent, "search")
     ) {
     echo 'not for robots!';
   else {
     echo 'outputting content... for real eyes only, Mr.Bond';



The site or URL referring to your site's URL can be determined using:

if (isset($_SERVER['HTTP_REFERER'])) {
  $incomingURL = $_SERVER['HTTP_REFERER'];



The Server object is accessible using:


For example the path of the current file may be accessible (depending on your server settings) using:


[21] [22]


The following gives you the incoming IP, however this may or may not be the actual IP of the user:

if (isset($_SERVER['HTTP_REFERER'])) {
  $incomingIP = $_SERVER['REMOTE_ADDR'];



The Session object is accessible using:


You can use a user-defined (such as USERNAME), for example:

if($username == $_SESSION["USERNAME"])

or, you can use a system-defined session property but must use the Request object, such as:




The Cookie object is accessed as such:


For example:

$preferences = $_SESSION["user_prefs"];



The new way to access databases via PHP is to use the generic PHP Data Objects (PDO) class (rather than mysql[26], mysqli[27], pgsql[28], DB2[29] and other specialty classes[30] previously used for each DB). The PDO extension supports over a dozen different DBMS/database servers and makes them accessible through a lightweight, consistent interface for accessing databases in PHP code. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions.

An example follows of how to use MySQL to connect to a database and perform a simple SELECT query:

/*** mysql db settings ***/
$hostname = 'localhost'; //db hostname
$username = 'username'; //db username
$password = 'password'; //db password
  try {
    $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
    echo 'Connected to database'; //output message saying we have connected
    $sql = 'SELECT first_name, last_name, position, salary FROM employee ORDER BY last_name DESC';
    foreach ($conn->query($sql) as $employee) {
       print $employee['first_name'] . ' ' . $employee['last_name'] . "\t";
       print $employee['position'] . "\t";
       print $employee['salary'] . "\n";
  catch(PDOException $e) {
    echo $e->getMessage();

[31] [32] [33] [34] [35] [36] [37] [38] [39] [40]


PHP has had support for HTML5 WebSockets since v5.5.0, as well as before that through custom C/C++/PHP/Flash libraries to polyfill missing features.


Cite error: Invalid <ref> tag; refs with no name must have content


Web Servers


PHP works natively with Apache. You literally start a new folder in 'htdocs' drop a PHP file in, and away you go!

PHP/Java/Tomcat BRIDGE

It is possible to bridge Java and PHP (among other combinations of programming languages) using a number of approaches. In particular, the following projects are the most successful PHP-Java and Java-PHP bridge efforts:


"All you need to do is to activate NTLM authentication in the Web server for the PHP pages that require that the user is logged in. If the Web server is Microsoft IIS, you only need to configure that kind of authentication in IIS configuration panel.

If the Web server is Apache, either running on Windows or Linux, you only need to activate and configure the mod_ntlm module.

From then on, if the user accessing the site is correctly logged, your PHP scripts only need to check the $_SERVER['LOGON_USER'] variable to determine the user name of the logged user. Actually LOGON_USER is the same variable that ASP and ASP.NET applications need to check because it is a setting that does not depend on the programming language that you use."[41]


[42] [43]


Smarty is a template engine for PHP. More specifically, it facilitates a managable way to separate application logic and content from its presentation. vThis is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person.


Symfony is one of the oldest PHP frameworks, and is designed for enterprise-level web applications. For all its power and performance, however, Symfony has a small footprint and is easy to configure on a variety of PHP hosting environments. Since it's been around for so long, you’ll find a lot of tutorials and books available on framework use, a perk for new users.


Extending the art & spirit of PHP, Zend Framework is based on simplicity, object-oriented best practices, corporate friendly licensing, and a rigorously tested agile codebase. Zend Framework is focused on building more secure, reliable, and modern Web 2.0 applications & web services, and consuming widely available APIs from leading vendors like Google, Amazon, Yahoo!, Flickr, as well as API providers and cataloguers like StrikeIron and ProgrammableWeb.



CodeIgniter is (as of v2.0) a PHP5.2+ MVC framework with a small footprint and great documentation. Often called a "beginner" framework because of its relative ease of use and short learning curve, CodeIgniter is nonetheless flexible and powerful.


PHP Framework For "Web Artisans".



Solar is a PHP 5 framework for web application development. It is fully name-spaced and uses enterprise application design patterns, with built-in support for localization and configuration at all levels.


FUSE is a Model View Controller framework for PHP. Taking influence from other web frameworks such as Ruby on Rails and CakePHP, then adding in custom, intuitive features of our own design, FUSE has developed into a robust, stable platform for MVC development using object oriented PHP.


Yii is a highly modular, high-performance PHP5 framework designed specifically for developing Web 2.0-style web applications. Yii uses a lot of command line generators and tools to get you up and running quickly; therefore, it's best used by people that aren't intimidated by a terminal window. All those generators mean more commands to memorize, but once you do, you'll find that they greatly decrease the time it takes to set up and configure your application.



It is possible to create PHP applications which run on a variety of desktop OS platforms. Some related tools are listed below.




[57] [58] [59]

External Links


  2. PHP 5 vs PHP 7:
  3. 5 New Features in PHP 7:
  4. 10 Things Not to Do in PHP 7 :
  5. What’s New in PHP 7.4 (Features, Deprecations, Speed):
  6. Evolution of PHP — v5.6 to v8.0:
  7. PHP 8.0 brings big updates. Here's what's new:
  8. Preparing for PHP 8 - New Features, Improvements, and Deprecations:
  9. PHP 8.0 Release Date and the status of JIT in PHP:
  10. The future of PHP 8 unclear:
  11. PHP 8 JIT benchmark:
  12. What's new in PHP 8.0:
  13. The “never” Return Type for PHP 8.1+:
  14. PHP 8.1 is coming — and it already promises to be one of the best releases:
  15. PHP 8 -- eight new features you need to know as a PHP Developer:
  16. How to check UserAgent?:
  17. PHP docs - get_browser:
  18. get_browser():
  19. Inspect the referrer in PHP:
  20. Determining Referer in PHP:
  21. See full list of pre-defined variables:
  22. Reserved $_SERVER variables:
  23. How to get the "REAL" IP Address of the incoming user/requester:
  24. $_SESSION:
  25. $_COOKIE:
  26. mysql connector (PHP 4.x):
  27. mysqli - MySQL Improved connector (PHP 5.x):
  28. pgsql - postgresql connector:
  29. IBM DB2 connector:
  30. Connecting PHP Applications to Apache Derby:
  31. (The only proper) PDO tutorial:
  32. PDO reference:
  33. PDO Tutorial for MySQL Developers: (before & after guide)
  34. Introduction to PHP PDO:
  35. (The only proper) PDO tutorial:
  36. AfterHours -- PDO catch up tutorial:
  37. Why you Should be using PHP's PDO for Database Access:
  38. implement LIKE query in PDO:
  39. PDO closing connection:
  40. PDO error: SQLSTATE[HY000]: General error: 2031:
  41. Microsoft promotes the careers of PHP professionals:
  42. 13 PHP Frameworks to Help Build Agile Applications:
  43. Top 20 Best PHP Frameworks for PHP Developers in 2015:
  44. Comparison of other PHP native functions and library alternatives:
  45. HipHop for PHP - Move Fast:
  46. Custom PHP.ini tips and tricks:
  47. Increase upload size in your php.ini:
  48. Is Number validation: (using is_numeric function)
  49. Build Blazing Fast PHP Websites with Memcached Distributed Caching -- Installing memcached:
  50. SHA384 is not supported by your openssl extension, could not verify the phar file integrity:
  51. Parsing a URL querystring into variables in PHP:
  52. PHP preg_replace - www or http://:
  53. Apache and PHP HTTP PUT Voodoo:
  54. Sending a file via HTTP PUT in PHP:
  55. Accessing Incoming PUT Data from PHP:
  56. failed loading cafile stream: `C:\xampp\apache\bin\curl-ca-bundle.crt':
  57. You Wouldn't Base64 a Password - Cryptography Decoded:
  58. Write Crypto Code! Don’t publish it!:
  59. How to Safely Implement Cryptography Features in Any Application:
  60. HTTP POST from PHP, without cURL:
  61. How to check if string contains substring PHP:

See Also

JSP | ASP | AJAX | jQuery | Flex | Apache Web Server | LAMP | File Upload