Welcompose
[ class tree: Welcompose ] [ index: Welcompose ] [ all elements ]

Class: Base_Database

Source Location: /base_classes/pdo.class.php

Class Overview


Project: Welcompose File: pdo.class.php


Author(s):

  • Andreas Ahlenstorf, sopic GmbH

Copyright:

  • 2008 creatics, Olaf Gleba

Variables

Methods



Class Details

[line 25]
Project: Welcompose File: pdo.class.php

Copyright (c) 2008 creatics

Project owner: creatics, Olaf Gleba 50939 Köln, Germany http://www.creatics.de

This file is licensed under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE v3 http://www.opensource.org/licenses/agpl-v3.html

$Id: pdo.class.php 50 2007-02-17 21:49:16Z andreas $




Tags:

author:  Andreas Ahlenstorf, sopic GmbH
copyright:  2008 creatics, Olaf Gleba
license:  GNU AFFERO GENERAL PUBLIC LICENSE v3


[ Top ]


Class Variables

$pdo =  null

[line 62]

The pdo database handle



Tags:

access:  protected

Type:   object


[ Top ]

$_affected_rows =  -1

[line 76]

Amount of affected rows



Tags:

access:  public

Type:   int


[ Top ]

$_backticks =  true

[line 70]

Enable/disable backticks

If enabled, backticks will automatically be added before and after every field name




Tags:

access:  protected

Type:   bool


[ Top ]

$_debug =  false

[line 82]

Display debug information or not



Tags:

access:  protected

Type:   bool


[ Top ]

$_driver_options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')

[line 49]

Array of pdo driver options



Tags:

access:  protected

Type:   array


[ Top ]

$_dsn =  null

[line 31]

Data Source Name (Connection information)



Tags:

access:  protected

Type:   string


[ Top ]

$_fetch_style =  PDO::FETCH_ASSOC

[line 88]

Fetch style (associative/numeric array etc) of

PDOStatement::fetch() and PDOStatement::fetchAll()




Tags:

access:  protected

Type:   mixed


[ Top ]

$_password =  null

[line 43]

Password to use when connecting to the database



Tags:

access:  protected

Type:   string


[ Top ]

$_table_alias_constants =  false

[line 56]

Whether to import a config file with table aliases and to turn them

into constants




Tags:

access:  protected

Type:   mixed


[ Top ]

$_username =  null

[line 37]

Username to use when connecting to the database



Tags:

access:  protected

Type:   string


[ Top ]



Class Methods


constructor __construct [line 117]

Base_Database __construct( array $params, array 1)

Create new database object

Supported params for $params:

  • dsn, string, required: Contains the information required to connect to the database
  • username, string, optional: The user name for the DSN string
  • password, string, optional: The password for the DSN string
  • driver_options, array, optional: A key=>value array of driver-specific connection options
  • debug, string, optional: Whether to enable the debug mode or not

Supported params for $options

  • debug, bool, optional: Whether to enable/disable the debug mode




Tags:

throws:  Base_DatabaseException
access:  public


Parameters:

array   1   Wrapper configuration
array   $params   Connection configuration

[ Top ]

destructor __destruct [line 181]

void __destruct( )

Database destructor

Closes connection to database




Tags:

access:  public


[ Top ]

method begin [line 660]

bool begin( )

Begin transaction

Disables autocommit mode and starts a new transaction. To re-enable the autocommit mode, call either Base_Database::commit() or Base_Database::rollback().




Tags:

access:  public


[ Top ]

method commit [line 678]

bool commit( )

Commit transaction

Commits a transaction and re-enables the autocommit mode.




Tags:

access:  public


[ Top ]

method delete [line 406]

int delete( string $table, [string $where = null], [array $bind_params = array()])

Delete row

Deletes existing row(s). First argument takes the table name, the second argument is the optional where clause. The fourth argument is a key=>value array of bind params for the where clause.




Tags:

return:  Affected rows
throws:  Base_DatabaseException
access:  public


Parameters:

string   $table   Table name
string   $where   Where clause
array   $bind_params   Bind params

[ Top ]

method execute [line 480]

int execute( string $sql, [array $bind_params = array()])

Execute query

Executes query without a return value. First argument takes the query string, the second argument takes a key=>value array of bind params.




Tags:

return:  Affected rows
throws:  Base_DatabaseException
access:  public


Parameters:

string   $sql   Query string
array   $bind_params   Bind params

[ Top ]

method insert [line 224]

int insert( string $table, array $data)

Insert new row

Inserts new row into table. First argument takes the table name, the second argument takes a key=>value array, where the key is the column name and the value is the data to insert into the column.




Tags:

return:  Insert id
throws:  Base_DatabaseException
access:  public


Parameters:

string   $table   Table name
array   $data   Row data

[ Top ]

method prepareBindParams [line 823]

array prepareBindParams( array $data)

Prepare bind params for where clause

Prepares the bind params for a where clause. The first argument is a key=>value array, where the key is the column name and the value is the data to insert into the column.




Tags:

throws:  Base_DatabaseException
access:  protected


Parameters:

array   $data   Row data

[ Top ]

method prepareInsertData [line 731]

array prepareInsertData( array $data)

Prepare data for insert

Prepares the query string and the bind params for an insert. The first argument is a key=>value array, where the key is the column name and the value is the data to insert into the column.




Tags:

throws:  Base_DatabaseException
access:  protected


Parameters:

array   $data   Row data

[ Top ]

method prepareUpdateData [line 777]

array prepareUpdateData( array $data)

Prepare data for update

Prepares the query string and the bind params for an update. The first argument is a key=>value array, where the key is the column name and the value is the data to insert into the column.




Tags:

throws:  Base_DatabaseException
access:  protected


Parameters:

array   $data   Row data

[ Top ]

method quote [line 714]

string quote( string $string, [int $type = PDO::PARAM_STR])

Quotes string for usage in query. Wrapps around PDO::quote. See the PHP manual for usage instructions.



Tags:

access:  public


Parameters:

string   $string  
int   $type  

[ Top ]

method resetAffectedRows [line 848]

void resetAffectedRows( )

Reset affected rows

Function to reset the value of Base_Database::_affected_rows.




Tags:

access:  protected


[ Top ]

method rollback [line 696]

bool rollback( )

Rollback transaction

Rolls back any work in progress and re-enables the autocommit mode.




Tags:

access:  public


[ Top ]

method select [line 558]

array select( string $sql, string $mode, [array $bind_params = array()])

Run a select

Runs a select against a database. The first argument takes the query string, the second argument the select mode. The third argument is an a key=>value array of bind params.

Valid select modes:

  • field: Returns only the value of a field
  • row: Returns only one row
  • multi: Returns an array containing multiple rows




Tags:

throws:  Base_DatabaseException
access:  public


Parameters:

string   $sql   Query string
string   $mode   Select mode
array   $bind_params   Bind params

[ Top ]

method update [line 304]

int update( string $table, array $data, [string $where = null], [array $bind_params = array()])

Update row

Updates existing row. First argument takes the table name, the second argument takes a key=>value array, where the key is the column name and the value is the data to insert into the column. Third argument is the optional where clause. The fourth argument is a key=>value array of bind params for the where clause.




Tags:

return:  Affected rows
throws:  Base_DatabaseException
access:  public


Parameters:

string   $table   Table name
array   $data   Row data
string   $where   Where clause
array   $bind_params   Bind params

[ Top ]

method _checkBindParamsFormat [line 995]

bool _checkBindParamsFormat( array &$bind_params)

Checks if provided array with bind params is in valid format. Takes array with bind params array as first argument. Returns boolean true.



Tags:

throws:  Base_DatabaseException
access:  protected


Parameters:

array   &$bind_params   Bind params array

[ Top ]

method _checkDataFormat [line 970]

bool _checkDataFormat( array &$data)

Checks if provided sql data is in valid format. Takes array with sql data array as first argument. Returns boolean true.



Tags:

throws:  Base_DatabaseException
access:  protected


Parameters:

array   &$data   Sql Data

[ Top ]

method _importTableAliasConstants [line 948]

bool _importTableAliasConstants( )

Imports table aliases.



Tags:

access:  protected


[ Top ]

method _sqliteTableExists [line 863]

bool _sqliteTableExists( string $table_name)

SQLite Table Exists

Utility function that checks if a table existis within a sqlite database. Takes the table name as first argument, returns bool.




Tags:

access:  public


Parameters:

string   $table_name   Table name

[ Top ]

method _stmtAutoGenParams [line 914]

array _stmtAutoGenParams( array $values)

Auto generate params

Auto generates params for prepared statements. Takes list of values as first argument. Returns array with three elements:

  • __param_names: List of bind param names
  • __param_list: List of bind param names for insert in query
  • __params: Array to append to $bind_params




Tags:

access:  public


Parameters:

array   $values   Value list

[ Top ]


Documentation generated on Sun, 08 Jan 2012 17:51:56 +0100 by phpDocumentor 1.4.3