ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:connect

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:reference:connect [2016/01/13 02:30] – ↷ Page moved from reference:connect to v5:reference:connect mnewnhamv5:reference:connection:connect [2023/05/07 10:37] (current) – Better return value description (boolean, not mixed) dregad
Line 5: Line 5:
 [[v5:database:connection_matrix|The Connection Matrix]] [[v5:database:connection_matrix|The Connection Matrix]]
 == Syntax == == Syntax ==
-   mixed connect(+   bool connect(
          optional string $parameter1 = '',          optional string $parameter1 = '',
          optional string $parameter2 = '',          optional string $parameter2 = '',
Line 15: Line 15:
 </WRAP> </WRAP>
 ===== Description ===== ===== Description =====
-The essential function ''connect()'' establishes a connection to a database using the provided parameters. The traditional description of the connection parameters is as follows: + 
--------------------------------------+The essential function ''connect()'' establishes a connection to a database using the provided parameters.  
 + 
 +Since ADOdb 5.21,0, some database drivers support the use of [[v5:reference:connection:setconnectionparameter|setConnectionParameter()]], which should be called before connect() to pass extra, database-specific parameters to the connect statement. 
 + 
 +The traditional description of the connection parameters is as follows: 
 ^ Parameter 1  ^ Parameter 2  ^ Parameter 3  ^ Parameter 4  ^ ^ Parameter 1  ^ Parameter 2  ^ Parameter 3  ^ Parameter 4  ^
 |  $hostName    $userId      $password    $database   | |  $hostName    $userId      $password    $database   |
Line 22: Line 27:
 However the actual values of the parameters for some databases are such that the actual requirements can be confusing. See the [[v5:database:connection_matrix|Connection Matrix]] for assistance. However the actual values of the parameters for some databases are such that the actual requirements can be confusing. See the [[v5:database:connection_matrix|Connection Matrix]] for assistance.
  
-If the connection is made, $db becomes a database connection object that can be used until the script ends. If the connection failsthe value is set to false.+If the connection is made, $db becomes a database connection object that can be used until the script ends.  
 + 
 +=== Return value === 
 + 
 +The method returns //true// if the connection was successfully established//false// otherwise. This should be checked before continuing with code execution.
  
 To debug the connection, set the value '' $db->debug = true; '' before calling the '' $db->connect '' statement To debug the connection, set the value '' $db->debug = true; '' before calling the '' $db->connect '' statement
Line 30: Line 39:
 /* /*
   Example using MySQL    Example using MySQL 
-*/+ */
 include 'adodb.inc.php'; include 'adodb.inc.php';
 /* /*
Line 40: Line 49:
  * Make a connection to a database on the local machine  * Make a connection to a database on the local machine
  */  */
-$db->connect('','user','password'.'employees');+$db->connect('', 'user', 'password''employees');
  
-/* 
-  
- */ 
 </code> </code>
v5/reference/connection/connect.1452648634.txt.gz · Last modified: 2017/04/21 11:36 (external edit)