DSN (Previous) (Next) クエリ

View this page in Last updated: Sun, 07 Sep 2008
English | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Plain HTML

接続

接続 -- データベースへの接続および接続の解除

説明

データベースオブジェクトを作成するには、MDB2 のいくつかのメソッドを使用します。

データベースに接続するには、 factory() connect() あるいは singleton() のいずれかの関数を使用します。 これらの関数には、最初のパラメータとして DSN を指定しなければなりません。このパラメータは、 文字列あるいは配列のどちらの形式でも指定できます。 配列を使用する場合は、配列の内容がデフォルトの情報にマージされます。
$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, // oci8 のみ
);
あなたが設定した要素がこのデフォルトを上書きし、残りはデフォルトのままとなります。

二番目のパラメータは、オプションの配列 $options で、このパッケージ用の実行時設定を指定します。

表 39-2オプションの一覧

名前説明
sslboolean 接続に ssl を使用するかどうかを指定します。
field_caseinteger CASE_LOWER あるいは CASE_UPPER のいずれかで、 フィールド名/テーブル名を強制的に小文字/大文字に変換します。
disable_queryboolean クエリを実行するかどうかを指定します。
result_classstring 結果セットに使用するクラスです。
buffered_result_classstring バッファリングした結果セットに使用するクラスで、デフォルトは MDB2_Result_Common です。
result_wrap_classstring 結果セットをラップするクラスで、デフォルトは MDB2_Result_Common です。
result_bufferingboolean 結果セットをバッファリングするかどうかを指定します。
fetch_classstring フェッチモードオブジェクトを使用する場合に用いるクラスです。
persistentboolean 持続的な接続を使用するかどうかを指定します。
debuginteger デバッグレベルを表す数値。
debug_handlerstring デバッグメッセージを受け取る関数/メソッド。
debug_expanded_outputboolean 過去との互換性のためのオプションで、 デバッグハンドラに詳細な情報を送るかどうかを指定します。
default_text_field_lengthinteger テキストフィールドのデフォルトの長さとして使用する値。
lob_buffer_lengthinteger LOB バッファの長さ。
log_line_breakstring 改行のフォーマット。
idxname_formatstring インデックス名における '%s' に使用するパターン。
seqname_formatstring シーケンス名における '%s' に使用するパターン。
savepoint_formatstring 自動生成されるセーブポイント名における '%s' に使用するパターン。
seqcol_namestring シーケンスカラムの名前。
quote_identifierboolean check_option の使用時に識別子のクォートを行うかどうか。
use_transactionsboolean トランザクションを使用するかどうか。
decimal_placesinteger 小数点以下で処理する桁数。
portabilityinteger 可搬性に関する定数。
modulesarray __call() で使用する、短いモジュール名と長いモジュール名との対応。
emulate_preparedboolean プリペアドステートメントを強制的にエミュレートします。
datatype_maparray ユーザ定義のデータ型と、その他のプリミティブデータ型との対応。
datatype_map_callbackarray コールされるコールバック関数/メソッド。

接続に成功すると、データベースクラスの新しいインスタンスを取得できます。 返される値を PEAR::isError() (これは、PEAR_Error およびそのサブクラスを検出します) あるいは MDB2_Driver_Common 独自の isError() で調べることを、強く推奨します。

接続を解除するには、データベースクラスのインスタンスの disconnect() メソッドを使用します。

DSN (Previous) (Next) クエリ

Download Documentation Last updated: Sun, 07 Sep 2008
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: CJ
A helpful note that took me days to figure out:

When connecting to a MSSQL database, specify the hostname as: "my.host.name,PORT". Don't use a colon, use a comma. That took so long!
Note by: user@example.com
In PHP5 all objects are passed by reference similar to the way Java does it.

From: http://www.php.net/manual/en/language.oop5.basic.php

"When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function. A copy of an already created object can be made by cloning it."
Note by: purej
Is this really true here ?
Quote: "new return reference automatically"
When i read it correctly its just for explicit usage of "new" but thats not the case, we use the Factory methods to get our MDB2 Object.
Note by: user@example.com
Note that using =& to assign objects is deprecated in PHP5:
"Since PHP 5, new return reference automatically so using =& in this context is deprecated and produces E_STRICT level message."