PHP

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

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

Specifications


Versions

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]


Language

PHAR

User-Agent

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';
   }
}

[16][17][18]

Referer

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

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

[19][20]

Server

The Server object is accessible using:

$_SERVER["property"];

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

$_SERVER['PATH_INFO'];

[21] [22]

IP

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'];
}

[23]

SESSION

The Session object is accessible using:

$_SESSION["property"];

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:

$_REQUEST['SESSION_NAME']

[24]


Cookies

The Cookie object is accessed as such:

$_SESSION["cookie_name"];

For example:

$preferences = $_SESSION["user_prefs"];

[25]


PDO

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:

<?php
/*** 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]


WebSockets

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.


Generators

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


Fibers



Web Servers

Apache

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:

PHP/.Net/IIS BRIDGE

"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.

http://modntlm.sourceforge.net/

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]



Frameworks

[42] [43]

Smarty

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

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.

Zend

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.

CakePHP

CodeIgniter

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.

Laravel

PHP Framework For "Web Artisans".

Konstrukt

SolarPHP

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

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

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.





Tools

Desktop

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

PHP-GTK


Resources


Tutorials



[57] [58] [59]


External Links



References

  1. PHP.net: http://php.net/
  2. PHP 5 vs PHP 7: https://www.geeksforgeeks.org/php-5-vs-php-7/
  3. 5 New Features in PHP 7: https://blog.teamtreehouse.com/5-new-features-php-7
  4. 10 Things Not to Do in PHP 7 : https://kinsta.com/blog/10-things-not-to-do-in-php-7/
  5. What’s New in PHP 7.4 (Features, Deprecations, Speed): https://kinsta.com/blog/php-7-4/
  6. Evolution of PHP — v5.6 to v8.0: https://medium.com/@meskis/evolution-of-php-v5-6-to-v8-0-c3514ebb7f28
  7. PHP 8.0 brings big updates. Here's what's new: https://www.techrepublic.com/article/programming-languages-php-8-0-brings-big-updates-heres-whats-new/
  8. Preparing for PHP 8 - New Features, Improvements, and Deprecations: https://www.zend.com/webinars/preparing-php-8-new-features-improvements-and-deprecations
  9. PHP 8.0 Release Date and the status of JIT in PHP: https://react-etc.net/entry/php-8-0-0-release-date-and-jit-status
  10. The future of PHP 8 unclear: https://react-etc.net/entry/the-future-of-php-8
  11. PHP 8 JIT benchmark: https://www.youtube.com/watch?v=a4y3UfkATbs
  12. What's new in PHP 8.0: https://www.youtube.com/watch?v=uU1-ZqIbYes
  13. The “never” Return Type for PHP 8.1+: https://betterprogramming.pub/the-never-return-type-for-php-802fbe2fa303
  14. PHP 8.1 is coming — and it already promises to be one of the best releases: https://medium.com/geekculture/php-8-1-is-coming-and-it-already-promises-to-be-one-of-the-best-releases-a86da2ed953f
  15. PHP 8 -- eight new features you need to know as a PHP Developer: https://reykario.medium.com/php-8-new-feature-you-need-to-know-as-php-developer-36d273750980
  16. How to check UserAgent?: http://icfun.blogspot.com/2008/07/php-how-to-check-useragent.html
  17. PHP docs - get_browser: http://www.php.net/manual/en/function.get-browser.php
  18. get_browser(): http://www.w3schools.com/php/func_misc_get_browser.asp
  19. Inspect the referrer in PHP: http://stackoverflow.com/questions/426825/inspect-the-referrer-in-php
  20. Determining Referer in PHP: http://stackoverflow.com/questions/165975/determining-referer-in-php
  21. See full list of pre-defined variables: http://php.net/manual/en/reserved.variables.php
  22. Reserved $_SERVER variables: http://php.net/manual/en/reserved.variables.server.php
  23. How to get the "REAL" IP Address of the incoming user/requester: http://snipplr.com/view/11484/
  24. $_SESSION: http://php.net/manual/en/reserved.variables.session.php
  25. $_COOKIE: http://php.net/manual/en/reserved.variables.cookies.php
  26. mysql connector (PHP 4.x): http://php.net/manual/en/book.mysql.php
  27. mysqli - MySQL Improved connector (PHP 5.x): http://php.net/manual/en/book.mysqli.php
  28. pgsql - postgresql connector: http://php.net/manual/en/book.pgsql.php
  29. IBM DB2 connector: http://php.net/manual/en/book.ibm-db2.php
  30. Connecting PHP Applications to Apache Derby: http://www.ibm.com/developerworks/data/library/techarticle/dm-0409casey/
  31. (The only proper) PDO tutorial: https://phpdelusions.net/pdo
  32. PDO reference: http://php.net/manual/en/book.pdo.php
  33. PDO Tutorial for MySQL Developers: https://web.archive.org/web/20170216121306/http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers (before & after guide)
  34. Introduction to PHP PDO: http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
  35. (The only proper) PDO tutorial: https://phpdelusions.net/pdo
  36. AfterHours -- PDO catch up tutorial: http://www.afterhoursprogramming.com/tutorial/PHP/PDO/
  37. Why you Should be using PHP's PDO for Database Access: https://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059
  38. implement LIKE query in PDO: http://stackoverflow.com/questions/11117134/implement-like-query-in-pdo#11117213
  39. PDO closing connection: https://stackoverflow.com/questions/18277233/pdo-closing-connection
  40. PDO error: SQLSTATE[HY000]: General error: 2031: https://stackoverflow.com/questions/17274556/pdo-error-sqlstatehy000-general-error-2031
  41. Microsoft promotes the careers of PHP professionals: http://www.phpclasses.org/blog/post/102-Microsoft-promotes-the-careers-of-PHP-professionals.html
  42. 13 PHP Frameworks to Help Build Agile Applications: http://mashable.com/2014/04/04/php-frameworks-build-applications/
  43. Top 20 Best PHP Frameworks for PHP Developers in 2015: http://www.k2ice.com/top-20-best-php-frameworks-for-php-developers-in-2015/
  44. Comparison of other PHP native functions and library alternatives: http://htmlpurifier.org/comparison
  45. HipHop for PHP - Move Fast: http://developers.facebook.com/blog/post/358
  46. Custom PHP.ini tips and tricks: http://www.askapache.com/php/custom-phpini-tips-and-tricks.html
  47. Increase upload size in your php.ini: http://drupal.org/node/97193
  48. Is Number validation: http://php.net/manual/en/function.is-numeric.php (using is_numeric function)
  49. Build Blazing Fast PHP Websites with Memcached Distributed Caching -- Installing memcached: http://www.phpbuilder.com/columns/php-memcached/Jason_Gilmore07282011.php3
  50. SHA384 is not supported by your openssl extension, could not verify the phar file integrity: https://stackoverflow.com/questions/54983039/sha384-is-not-supported-by-your-openssl-extension-could-not-verify-the-phar-fil
  51. Parsing a URL querystring into variables in PHP: https://web.archive.org/web/20130315210836/http://www.askaboutphp.com/23/parsing-url-queryingstring.html
  52. PHP preg_replace - www or http://: https://stackoverflow.com/questions/6165552/php-preg-replace-www-or-http
  53. Apache and PHP HTTP PUT Voodoo: http://www.evardsson.com/blog/2010/04/27/apache-and-php-http-put-voodoo/
  54. Sending a file via HTTP PUT in PHP: http://stackoverflow.com/questions/1691530/sending-a-file-via-http-put-in-php
  55. Accessing Incoming PUT Data from PHP: http://www.lornajane.net/posts/2008/Accessing-Incoming-PUT-Data-from-PHP
  56. failed loading cafile stream: `C:\xampp\apache\bin\curl-ca-bundle.crt': https://stackoverflow.com/questions/55488982/failed-loading-cafile-stream-c-xampp-apache-bin-curl-ca-bundle-crt
  57. You Wouldn't Base64 a Password - Cryptography Decoded: https://paragonie.com/blog/2015/08/you-wouldnt-base64-a-password-cryptography-decoded
  58. Write Crypto Code! Don’t publish it!: https://www.cryptofails.com/post/75204435608/write-crypto-code-dont-publish-it
  59. How to Safely Implement Cryptography Features in Any Application: https://paragonie.com/blog/2015/09/how-to-safely-implement-cryptography-in-any-application
  60. HTTP POST from PHP, without cURL: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/
  61. How to check if string contains substring PHP: http://www.maxi-pedia.com/string+contains+substring+PHP

See Also

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