Manuel Pear
Connecting
Description
To instantiate a database object you have several methods available using MDB2.
Tableau 39-1. Connection functions
| Function | Summary | Description |
|---|---|---|
| factory() | Efficient | Will instantiate a new MDB2_Driver_Common instance, but will not connect to the database until required. This will delay making the actual connection. This is called lazy connecting. Using this makes sense if it is possible that due to caching inside the application no connection will ever need to be established. |
| connect() | Eager | Will instantiate a new MDB2_Driver_Common instance, and will establish a database connection immediately. This way any connection issues will immediately raise an error. |
| singleton() | Available | Returns a MDB2_Driver_Common instance. A new MDB2_Driver_Common object is only created once using factory(), subsequent calls to singleton will return a reference to the existing object. This method is preferred over declaring your database object as a global. |
$dsn = array(
'phptype' => false,
'dbsyntax' => false,
'username' => false,
'password' => false,
'protocol' => false,
'hostspec' => false,
'port' => false,
'socket' => false,
'database' => false,
'new_link' => false,
'service' => false, // only in oci8
);
|
The second parameter is the optional $options array that can contain runtime configuration settings for this package.
Tableau 39-2. List of options
| Name | Type | Description |
|---|---|---|
| ssl | booléen | determines if ssl should be used for connections |
| field_case | entier | CASE_LOWER|CASE_UPPER: determines what case to force on field/table names |
| disable_query | booléen | determines if queries should be executed |
| result_class | chaîne de caractères | class used for result sets |
| buffered_result_class | chaîne de caractères | class used for buffered result sets, default is MDB2_Result_Common |
| result_wrap_class | chaîne de caractères | class used to wrap result sets into, default is MDB2_Result_Common |
| result_buffering | booléen | should results be buffered or not? |
| fetch_class | chaîne de caractères | class to use when fetch mode object is used |
| persistent | booléen | persistent connection? |
| debug | entier | numeric debug level |
| debug_handler | chaîne de caractères | function/method that captures debug messages |
| debug_expanded_output | booléen | BC option to determine if more context information should be send to the debug handler |
| default_text_field_length | entier | default text field length to use |
| lob_buffer_length | entier | LOB buffer length |
| log_line_break | chaîne de caractères | line-break format |
| idxname_format | chaîne de caractères | pattern with '%s' for index name |
| seqname_format | chaîne de caractères | pattern with '%s' for sequence name |
| savepoint_format | chaîne de caractères | pattern with '%s' for auto generated savepoint names |
| seqcol_name | chaîne de caractères | sequence column name |
| quote_identifier | booléen | if identifier quoting should be done when check_option is used |
| use_transactions | booléen | if transaction use should be enabled |
| decimal_places | entier | number of decimal places to handle |
| portability | entier | portability constant |
| modules | array | short to long module name mapping for __call() |
| emulate_prepared | booléen | force prepared statements to be emulated |
| datatype_map | array | map user defined datatypes to other primitive datatypes |
| datatype_map_callback | array | callback function/method that should be called |
In case of success you get a new instance of the database class. It is strongly recommended to check this return value with PEAR::isError() (will detect PEAR_Error or any subclass) or the MDB2_Driver_Common specific isError().
To disconnect use the method disconnect() from your database class instance.
Remonter 
