v5:reference:connection:adonewconnection
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
reference:adonewconnection [2015/07/26 16:20] – created mnewnham | v5: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 error. This behavior will be removed in version 6.0.0. | ||
- | </ | ||
<WRAP right box> | <WRAP right box> | ||
- | == Syntax | + | == Syntax == |
- | + | ||
mixed adoNewConnection( | mixed adoNewConnection( | ||
optional string $driverType='' | optional string $driverType='' | ||
) | ) | ||
- | + | ||
- | == Syntax version 6.0.0 == | + | |
- | mixed adoNewConnection( | + | |
- | string $driverType | + | |
- | ) | + | |
</ | </ | ||
===== Description ===== | ===== Description ===== | ||
- | The function adoNewConnection, | + | The function adoNewConnection, |
+ | |||
+ | ===== 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 '' | ||
+ | |||
+ | ** | ||
+ | < | ||
+ | "valid driver name" + "://" | ||
+ | </ | ||
+ | ** | ||
+ | |||
+ | 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: | ||
+ | ===== Usage ===== | ||
+ | ==== Simple Usage ==== | ||
+ | <code php> | ||
+ | include ' | ||
+ | /* | ||
+ | * Simple connection | ||
+ | */ | ||
+ | $driver = ' | ||
+ | $db = adoNewConnection($driver); | ||
+ | /* | ||
+ | * Now connect to the database | ||
+ | */ | ||
+ | $db-> | ||
+ | </ | ||
+ | ==== DSN Usage ==== | ||
+ | <code php> | ||
+ | include ' | ||
+ | /* | ||
+ | * Set DSN | ||
+ | */ | ||
+ | $driver = ' | ||
+ | $DSN = " | ||
+ | $db = adoNewConnection($driver . '://' | ||
+ | /* | ||
+ | * 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 ^ Driver | ||
+ | | new | ||
+ | | persist | ||
+ | | persistent | ||
+ | | debug | ||
+ | | port | mysqli, postgres9 | ||
+ | | socket | ||
+ | | nls_date_format | ||
+ | | cachesecs | ||
+ | | memCache | ||
+ | | memCacheHost | ||
+ | | memCachePort | ||
+ | | memCacheCompress | ||
+ | |||
+ | ===== Error Codes ===== | ||
+ | Note that, because no connection object is available, the codes cannot be retrieved via [[v5: | ||
+ |
v5/reference/connection/adonewconnection.1437920415.txt.gz · Last modified: 2017/04/21 11:37 (external edit)