Difference between revisions of "PHP111"

From mi-linux
Jump to navigationJump to search
Line 3: Line 3:
 
= PHP and Databases – Making the Connection =
 
= PHP and Databases – Making the Connection =
  
== There are 3 ways to connect to a database in PHP:
+
== How to connect ==
 +
 
 +
There are 3 ways to connect to a database in PHP:
  
 
# (DEPRECATED) The [http://www.php.net/manual/en/ref.mysql.php mysql functions] are procedural and use manual escaping.
 
# (DEPRECATED) The [http://www.php.net/manual/en/ref.mysql.php mysql functions] are procedural and use manual escaping.

Revision as of 15:24, 29 June 2016

Main Page >> Web Application Development >> Workbook >> PHP and Databases

PHP and Databases – Making the Connection

How to connect

There are 3 ways to connect to a database in PHP:

  1. (DEPRECATED) The mysql functions are procedural and use manual escaping.
  2. MySQLi is a replacement for the mysql functions, with object-oriented and procedural versions. It has support for prepared statements.
  3. PDO (PHP Data Objects) is a general database abstraction layer with support for MySQL among many other databases. It provides prepared statements, and significant flexibility in how data is returned.


Ready to try some more PHP/MySQL?

A simple example of using a HTML form to capture search requirements and execute a custom query can be found at PHP112 - Simple HTML/PHP/MySQL example