PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

PDOStatement> <PDO
Last updated: Fri, 05 Sep 2008

view this page in

PDO::setAttribute

(PHP 5 >= 5.1.0, PECL pdo:0.1-1.0.3)

PDO::setAttribute 属性を設定する

説明

bool PDO::setAttribute ( int $attribute , mixed $value )

データベースハンドルの属性を設定します。 利用可能な通常の属性は以下の一覧の通りです。いくつかのドライバでは、 ドライバ固有の属性を使用することが可能です。

  • PDO::ATTR_CASE: 強制的にカラム名を指定したケースにする

    • PDO::CASE_LOWER: 強制的にカラム名を小文字にする

    • PDO::CASE_NATURAL: データベースドライバによって返されるカラム名をそのままにする

    • PDO::CASE_UPPER: 強制的にカラム名を大文字にする

  • PDO::ATTR_ERRMODE: エラーレポート

    • PDO::ERRMODE_SILENT: エラーコードのみ設定する

    • PDO::ERRMODE_WARNING: E_WARNING を発生させる

    • PDO::ERRMODE_EXCEPTION: 例外 を投げる

  • PDO::ATTR_ORACLE_NULLS (Oracle だけでなく、全てのドライバで利用可能): NULL とから文字列の変換

    • PDO::NULL_NATURAL: 変換しない

    • PDO::NULL_EMPTY_STRING: 空文字は NULL に変換される

    • PDO::NULL_TO_STRING: NULL は空文字に変換される

  • PDO::ATTR_STRINGIFY_FETCHES: フェッチする際、数値を文字列に変換する。bool を必要とする

  • PDO::ATTR_STATEMENT_CLASS: PDOStatement に由来するユーザーが提供するステートメントクラスを設定する。 永続的な PDO インスタンスは使用できない。 array(string classname, array(mixed constructor_args)) を必要とする。

  • PDO::ATTR_AUTOCOMMIT (OCI, Firebird そして MySQL で利用可能): それぞれの単一文で自動コミットするかどうか。

  • PDO::MYSQL_ATTR_USE_BUFFERED_QUERY (MySQL で利用可能): バッファされたクエリを使用する。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。



PDOStatement> <PDO
Last updated: Fri, 05 Sep 2008
 
add a note add a note User Contributed Notes
PDO::setAttribute
colinganderson [at] gmail [dot] com
18-May-2007 11:59
Because no examples are provided, and to alleviate any confusion as a result, the setAttribute() method is invoked like so:

setAttribute(ATTRIBUTE, OPTION);

So, if I wanted to ensure that the column names returned from a query were returned in the case the database driver returned them (rather than having them returned in all upper case [as is the default on some of the PDO extensions]), I would do the following:

<?php
// Create a new database connection.
$dbConnection = new PDO($dsn, $user, $pass);

// Set the case in which to return column_names.
$dbConnection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
?>

Hope this helps some of you who learn by example (as is the case with me).

.Colin
gregory dot szorc at gmail dot com
15-Feb-2007 01:32
It is worth noting that not all attributes may be settable via setAttribute().  For example, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE is only settable in PDO::__construct().  You must pass PDO::MYSQL_ATTR_MAX_BUFFER_SIZE as part of the optional 4th parameter to the constructor.  This is detailed in http://bugs.php.net/bug.php?id=38015
Tobi
21-Nov-2006 08:11
Hint: setting the PDO::ATTR_ERRMODE attribute to PDO::ERRMODE_EXCEPTION
worked for me only with Mysql 4.x - I took me some time to figure this out ;-)
m dot leuffen at gmx dot de
26-Jul-2006 10:44
Hi,

if you are wondering about a size-bound (1 MB) on blob and text fields after upgrading to PHP5.1.4. You might try to increase this limit by using the setAttribute() method.

This will fail. Instead use the options array when instantiating the pdo:

$pdo = new PDO ("connection_settings", "user", "pass", array
(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>1024*1024*50));

This should fix the problem and increase the limit to 50 MB.

Bye,
  Matthias

PDOStatement> <PDO
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites