This is an old revision of the document!
adoNewConnection
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.
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.
Syntax before version 6.0.0
mixed adoNewConnection( optional string $driverType='' )
Syntax version 6.0.0
mixed adoNewConnection( string $driverType )
Description
The function adoNewConnection, in the simple form, loads the database driver specific files as specified by the string $driverType
. The driver name must match the name of a file adodb-$driverType-inc.php
in the adodb/drivers
directory. As there is no 'master list' of drivers, the driver can be named anything, it's existence in this directory is the only way of checking it's validity. This simplicity makes it easy to create a new driver.
Passing a connection DSN
In addition to the simple form, a DSN connection string can be passed to any database that supports that connection type. The $driverType
string must be in the following format:
"valid driver name" + "://" + "standard DSN string"
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 connect() statement.
Usage
Simple Usage
include 'adodb.inc.php'; /* * Simple connection */ $db = adoNewConnection('mysqli'); /* * Now connect to the database */ $db->connect('localhost','user','password','employees');
DSN Usage
include 'adodb.inc.php'; /* * Set DSN */ $DSN = "user:password@localhost/employees"; $db = adoNewConnection('mysqli'+ '://' + $DSN); /* * Now connected */
Error Codes
As of version 6.0.0 , the following error codes will be returned if a connection fails.
Code | Description |
---|---|
-1 | An invalid driver name was given |
-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 errorMsg()