- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:reference:connection:adonewconnection

# adoNewConnection

##### Syntax

    mixed adoNewConnection(
        optional 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
     */
    $driver = 'mysqli';
    $db     = adoNewConnection($driver);
    /*
     * Now connect to the database
     */
    $db->connect('localhost','user','password','employees');

### DSN Usage

    include 'adodb.inc.php';
    /*
     * Set DSN
     */
    $driver = 'mysqli';
    $DSN    = "user:password@localhost/employees";
    $db     = adoNewConnection($driver + '://' + $DSN);
    /*
     * Now connected
     */

## 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.

Code | Value | Parameter | Description
--- | --- | --- | ---
new | true | nConnect() | Forces a new connection
persist | true | pConnect() | Creates a persistent connection
persistent | true | pConnect() | Creates a persistent connection
debug | true | debug | Enables debug mode
role | string | When using the ibase driver, allows setting a role
dialect | integer | Undocumented option
charset | string | setCharSet() | Sets a character set
buffers | string | Undocumented option
fetchmode | int | setFetchMode() | Sets the fetch mode
charpage | string | Undocumented option
clientflags | string | Undocumented option
port | int | Sets the connection port
socket | int | Sets the connection socket
nls_date_format | string | Set date format |
cachesecs | int | Sets the number of cache seconds |
memcache | string | Undocumented series of options

## Error Codes

Note that, because no connection object is available, the codes cannot be retrieved via errorMsg()

v5/reference/connection/adonewconnection.txt · Last modified: 2016/01/17 06:29 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top