ご注意ください

このWikiに書かれた情報は、Risoluto1.x系に関するものです。 Risoluto1.x系は開発が終了しており、現在Risoluto2.x系の開発が進められています。

最近の更新

2012-10-11
2012-04-05
2012-03-27

最新リリース情報

risoluto (1.3.1)2011-09-27 15:41
risoluto-upgrade (1.3.0 to 1.3.1)2011-10-24 15:51
simpleblog (1.4.0)2011-10-19 14:50
simpleblog-upgrade (1.2.0 to 1.3.0)2011-07-21 23:13
simplepage (1.3.0)2011-10-19 14:45
simplepage-upgrade (1.1.0 to 1.2.0)2011-07-21 23:15

Wikiガイド

サイドバー

Return

Class reference:RisoluteDb Class(risoluto_db.php)

Abstruction of the Class

It is a wrapper class of PEAR::MDB2. It enables various operations toward DB. It is not only just a wrapper method, but also has methods to ease processes related to DB and often used for DB processing.

How to create class instance

  1. require_once( RISOLUTO_FUNC . 'risoluto_db.php' );
  2. $instance = new RisoluteDb();

What this class depends on

  • PEAR::MDB2
  • PEAR::MDB2_Drivers_*

Contents of class

Class variable

$obj_instance

Scopeprivate(static)
Typeobject
PurposeIt keeps the instance itself for singleton pattern.

$obj_db

Scopeprivate(static)
Typeobject
PurposeKeeping information of MDB2_Driver_Common.

Class method

__construct()

Scopeprivate
ParameterN/A
Return valueN/A
PurposeConstructor for this present class (prosesses nothing).

__clone()

Scopeprivate
ParameterN/A
Return valueN/A
Type of Return valueN/A
PurposeClone method of this present class (prosesses nothing).

singleton()

Scopepublic(static)
ParameterN/A
Return valueN/A
Type of Return valueN/A
PurposeCreates and returns this present instance with singleton pattern.

dbConnect()

Scopepublic
Parameterstring $dsnid DSN
Return valueResult for execution of function (true: normal end / false: abnormal end)
Type of Return valueboolean
PurposeConnect to DB with using DNS given as a parameter.
  1. $result = $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. var_dump( $result );

dbDisConnect()

Scopepublic
ParameterN/A
Return valueResult for execution of function (true: normal end / false: abnormal end)
Type of Return valueboolean
PurposeClose connection to DB.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->dbDisConnect();
  3. var_dump( $result );

dbCommit()

Scopepublic
ParameterN/A
Return valueResult for execution of function (true: normal end / false: abnormal end)
Type of Return valueboolean
PurposeCommits transaction.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $instance->dbBeginTransaction();
  3. $result = $instance->dbCommit();
  4. $instance->dbDisConnect();
  5. var_dump( $result );

dbRollback()

Scopepublic
ParameterN/A
Return valueResult for execution of function (true: normal end / false: abnormal end)
Type of Return valueboolean
PurposeRolls back transaction.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $instance->dbBeginTransaction();
  3. $result = $instance->dbRollback();
  4. $instance->dbDisConnect();
  5. var_dump( $result );

dbBeginTransaction()

Scopepublic
ParameterN/A
Return value|Result for execution of function (true: normal end / false: abnormal end)
Type of Return valueboolean
PurposeStarts transaction.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->dbBeginTransaction();
  3. $instance->dbRollback();
  4. $instance->dbDisConnect();
  5. var_dump( $result );

dbSetOptions()

Scopepublic
ParameterN/A
Return valuealways true
Type of Return valueboolean
PurposeSets up options of MDB2. Setting values are hard-coded, and it's automatically called when connection by dbConnect() succeeds.

dbGetErrMsg()

Scopepublic
Parameterobject $obj_err MDB:ERROR object (can be omitted)
Return valueAcquired error message
Type of Return valuestring
PurposeAcquires error messages from MDB::ERROR in case it's assigned, if not, acquires from class variable ($obj_db).
  1. $result = $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. if ( PEAR::isError( $result ) )
  3. {
  4. var_dump( $instance->dbGetErrMsg( $result ) );
  5. }

dbGetAll()

Scopepublic
Parameterstring $query SQL query to execute ('?' in query is a place holder)/Arrayed SQL to store a replacing value of string $param place holder
Return valueResult of query execution (for error happens, DB:ERROR object)
Type of Return valuearray
PurposeExecutes query assigned by Parameter, then acquires result as array.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->dbGetAll( 'select col1,col2 from table where key = ?', array( 'key' ) );

And an example of aquired result is as follows:

  1. [0] = array(
  2. array(
  3. 'col1' => 'value1'
  4. ,'col2' => 'value2'
  5. )
  6. )
  7. ,[1] = array(
  8. array(
  9. 'col1' => 'value1'
  10. ,'col2' => 'value2'
  11. )
  12. )

dbGetRow()

Scopepublic
Parameterstring $param SQL query to execute ('?' in query is a place holder)/Arrayed SQL to store a replacing value of string $param place holder
Return valueResult of query execution (for error happens, DB:ERROR object)
Type of Return valuearray
PurposeExecutes query assigned by Parameter, then acquires result as array.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->dbGetRow( 'select col1,col2 from table where key = ?', array( 'key' ) );
  3. var_dump( $result );

And the acquisition result is as follows:

  1. array(
  2. 'col1' => 'value1'
  3. ,'col2' => 'value2'
  4. )

dbExecSQL()

Scopepublic
Parameterstring $param SQL query to execute ('?' in query is a place holder)/Arrayed SQL to store a replacing value of string $param place holder
Return valueResult of query execution (for error happens, DB:ERROR object)
Type of Return valuemixed
PurposeExecutes query assigned by Parameter. Mainly used to publish SQL except for SELECT such as INSERT/UPDATE/DELETE.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->dbExecSQL( 'insert into table( col1,col2 ) values ( ?, ? )', array( 'value1','value2' ) );
  3. var_dump( $result );

fileSQLExec()

Scopepublic
Parameterstring $path File includes SQL to execute
Return valueResult of execution (true: all executed normally/false: some or all failed)
Type of Return valueboolean
PurposeExecutes SQL in the file assigned by Parameter. Each SQL in the file should be delimitted by ';', though line feed or space can be written freely.
  1. $instance->dbConnect( 'phptype://username:password@hostspec/database' );
  2. $result = $instance->fileSQLExec( '/tmp/sql.txt' );
  3. var_dump( $result );

Return