ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:adonewconnection

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
reference:adonewconnection [2015/07/26 18:20] mnewnhamv5:reference:connection:adonewconnection [2020/12/08 10:39] (current) – better use PHP string concatenation for example instead of javascript's ;-) peterdd
Line 1: Line 1:
 ====== adoNewConnection ====== ====== adoNewConnection ======
 ~~NOTOC~~ ~~NOTOC~~
-<WRAP alert> 
-Not passing a driver name as the parameter to this function does nothing but return an html string indication that the no driver name was passed. This behavior will be removed in version 6.0.0. 
-</WRAP> 
-<WRAP alert> 
-Passing an invalid or missing driver name as the parameter to this function returns an html formatted string. This behavior will be change in version 6.0.0. If an error occurs, the function will return a numeric error. See the guide below. 
-</WRAP> 
 <WRAP right box> <WRAP right box>
-== Syntax before version 6.0.0 == +== Syntax == 
-  +
   mixed adoNewConnection(   mixed adoNewConnection(
       optional string $driverType=''       optional string $driverType=''
   )   )
-  +
-== Syntax version 6.0.0 == +
-  mixed adoNewConnection( +
-      string $driverType +
-  ) +
 </WRAP> </WRAP>
 ===== Description ===== ===== Description =====
Line 31: Line 21:
 ** **
  
-If the DSN string parses correctly, an attempt is made to automatically connect to the database. If the connection succeeds, then there is no need to issue a [[reference:connect|connect()]] statement.+If the DSN string parses correctly, an attempt is made to automatically connect to the database. If the connection succeeds, then there is no need to issue a [[v5:reference:connection:connect|connect()]] statement.
 ===== Usage ===== ===== Usage =====
 ==== Simple Usage ==== ==== Simple Usage ====
Line 37: Line 27:
 include 'adodb.inc.php'; include 'adodb.inc.php';
 /* /*
- * Simple connection +* Simple connection 
- */+*/
 $driver = 'mysqli'; $driver = 'mysqli';
 $db     = adoNewConnection($driver); $db     = adoNewConnection($driver);
 /* /*
- * Now connect to the database +* Now connect to the database 
- */+*/
 $db->connect('localhost','user','password','employees'); $db->connect('localhost','user','password','employees');
 </code> </code>
Line 50: Line 40:
 include 'adodb.inc.php'; include 'adodb.inc.php';
 /* /*
- * Set DSN +* Set DSN 
- */+*/
 $driver = 'mysqli'; $driver = 'mysqli';
 $DSN    = "user:password@localhost/employees"; $DSN    = "user:password@localhost/employees";
-$db     = adoNewConnection($driver '://' $DSN);+$db     = adoNewConnection($driver '://' $DSN);
 /* /*
- * Now connected +* Now connected 
- */+*/
 </code> </code>
 +===== Additional Parameters To DSN connection ====
 +The following additional parameter can be added to the DSN connection string. Some of the parameters only work with specific drivers.
  
-===== Error Codes ===== +^ Code              ^ Driver             ^ Value                                      ^ Parameter                                        ^ Description                                                          ^ 
-As of version 6.0.0 , the following error codes will be returned if a connection fails.+| new                                  | true                                       | [[v5:reference:connection:nconnect|nConnect()]]  | Forces a new connection                                              | 
 +| persist                              | true                                       | [[v5:reference:connection:pconnect|pConnect()]]  | Creates a persistent connection                                      | 
 +| persistent        |                    | true                                       | [[v5:reference:connection:pconnect|pConnect()]]  | Creates a persistent connection                                      | 
 +| debug                                | true| [[v5:userguide:debug|debug]]                                                            | Enables debug mode                                                   | 
 +| port              | mysqlipostgres9  | int                                                                                         | Sets the connection port                                             | 
 +| socket            | mysqli             | string |                    | Sets the connection socket | 
 +| nls_date_format   | oci8               | string |                    | Set date format            | 
 +| cachesecs                            | int    |                                                                                      | Sets the number of cache seconds                                     | 
 +| memCache          |                    | false |[[v5:userguide:memcached|memcache]]                                                    | Enables memcache library for caching                                 | 
 +| memCacheHost      |                    | array |[[v5:userguide:memcached|memcache]]                                                    | Array of one or more memcached servers                               | 
 +| memCachePort      |                    | int   |[[v5:userguide:memcached|memcache]]                                                      | Optional alternative port to connect to memcache server(s)           | 
 +| memCacheCompress  |                    | false |[[v5:userguide:memcached|memcache]]                                                    | Enables memcache compression (not supported with memcached library)  |
  
-^Code^Description^ +===== Error Codes ===== 
-|-1|An invalid driver name was given| +Note that, because no connection object is available, the codes cannot be retrieved via [[v5:reference:connection:errormsg|errorMsg()]]
-|-2|Unable to parse DSN string| +
-|-3|Connection to database via DSN string failed|+
  
-Note that, because no connection object is available, the codes cannot be retrieved via [[reference:errorMsg|errorMsg()]] 
  
v5/reference/connection/adonewconnection.1437927643.txt.gz · Last modified: 2017/04/21 11:37 (external edit)