ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_abstraction:establishing_connection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
v5:userguide:learn_abstraction:establishing_connection [2016/03/15 01:14] – created mnewnhamv5:userguide:learn_abstraction:establishing_connection [2016/03/15 17:31] (current) – [Including The ADOdb libraries] review dregad
Line 1: Line 1:
 <- v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:basic_query|A Basic Query -> <- v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:basic_query|A Basic Query ->
 +~~NOTOC~~
 ====== Establishing A Connection ====== ====== Establishing A Connection ======
- connection needs to be first established to the database. The parameters required to connect to the database are the same as when using a direct PHP connection. For detailed information about connections see [[v5:reference:connection:connect|connect()]]+Before interacting with data, a connection needs to be first established to the database. The parameters required to connect to the database are the same as when using a direct PHP connection. For detailed information about connectionssee [[v5:reference:connection:connect|connect()]]
 + 
 +===== Selecting A Driver ===== 
 +In addition to ensuring the correct database connection driver is available in the PHP configuration, a matching ADOdb driver must be selected. As a general rule, the **Native Mode** drivers (e.g. mysqli, postgres9, oci8) are faster and have more features than generic drivers (e.g. odbc_mssql2012, pdo_access), so if you have the choice, you should select one of those. 
 +===== Including The ADOdb libraries ===== 
 +ADOdb versions 5 and lower do not support class autoloading, so the base library must be included in all the programs that use its features. Only the base class need be included, if required extended features are , they will be automatically included. See also the [[project:include_file_guide|Include File Guide]]. 
  
 <code php> <code php>
 include 'adodb_dir/adodb.inc.php'; include 'adodb_dir/adodb.inc.php';
 +/*
 +* This is the driver you have selected to use
 +*/
 +$driver = 'mysqli';
  
-$db = newAdoConnection('odbc');+$db = newAdoConnection($driver); 
 + 
 +/* 
 +* These are the parameters required to connect to the database see connect() 
 +*/ 
 + 
 $db->connect($parameters); $db->connect($parameters);
 </code> </code>
 +
 The returned ''$db'' object is used for all ADOdb activity. If the connection fails, the connect statement returns false and an error is logged. The returned ''$db'' object is used for all ADOdb activity. If the connection fails, the connect statement returns false and an error is logged.
  
Line 16: Line 32:
      
 can be executed.  can be executed. 
 +===== Debugging Connection Failures =====
 +ADOdb provides a debugging mode, set simply by setting the parameter
 +  $db->debug = true;
 +
 +The earliest that it can be set is after the creation of the ''$db'' connection object. It can also be switched on or off as required. For more information, see [[v5:userguide:debug|Debugging Guide]].
 + 
v5/userguide/learn_abstraction/establishing_connection.1458000858.txt.gz · Last modified: 2017/04/21 11:40 (external edit)