tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Class: DB_Connection

Source Location: /db/db_connection.class.php

Class DB_Connection

Descendants
Child Class Description
DB_Connection_Installer This class is ment to be used ONLY by module installers

[ Top ]
Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From Tangra_Class

Tangra_Class::get_class_name()
Alias of get_class(). Exist because of historical reasons.
Tangra_Class::__set()
Overides PHP built-in method and just throws exception if called. Purpose - to "forbid" autosetting of nonexisting class properties.

[ Top ]
Property Summary
integer   $autocommit   Autocommit mode
unknown_type   $conn   DB connection itself (resource)
boolean   $connected   Is connected to DB?
string   $dsn   DB DSN

[ Top ]
Method Summary
static void   execute_in_trans()   Executes sql statemnt(s) in transaction
boolean   __construct()   Constructor
void   __destruct()   Destructor
void   complete_trans()   Finishing transaction
void   connect()   Tries to connect to DB
void   disconnect()   Disconnects from the DB
void   execute()   Executes SQL statemnt
void   fail_trans()   Manually marking transaction as failed
void   generate_id()   Generates next id from sequence
unknown   get_autocommit()   Gets autocommit mode
unknown   get_conn()   Returns internal db connection object
unknown   get_dsn()   Gets DB DSN
void   get_error_msg()   Returns error message if any
boolean   is_connected()   Gets $this->connected
boolean   is_like_sql_injection()   Checks if $sql looks like SQL injection attempt
void   query()   Alias of execute()
string   remove_quoted()   Removes quoted content from $sql_str
void   select_limit()   Selects limited ammount of rows
void   set_autocommit()   Sets autocommit mode
void   set_connected()   Sets $this->connected
void   start_trans()   Starting transaction
string   _remove_quoted_with()   Removes quoted with $q from $sql_str

[ Top ]
Properties
integer   $autocommit [line 56]

Autocommit mode

API Tags:
Access:  private


[ Top ]
unknown_type   $conn [line 48]

DB connection itself (resource)

API Tags:
Access:  protected


[ Top ]
boolean   $connected = false [line 32]

Is connected to DB?

API Tags:
Access:  private


[ Top ]
string   $dsn [line 40]

DB DSN

API Tags:
Access:  private


[ Top ]
Methods
static method execute_in_trans  [line 222]

  static void execute_in_trans( DB_Connection $dbc, mixed $sql  )

Executes sql statemnt(s) in transaction

Parameters:
DB_Connection   $dbc: 
mixed   $sql: 

API Tags:
Access:  public


[ Top ]
Constructor __construct  [line 67]

  boolean __construct( string $dsn  )

Constructor

Attempts to connect to database specified with dsn

Parameters:
string   $dsn:  Valid DSN

API Tags:
Return:  returns true on success, flase otherwise


Redefined in descendants as:

[ Top ]
Destructor __destruct  [line 193]

  void __destruct( )

Destructor

Here is the place to disconnect nicely from the database


API Tags:
Abstract:  


Redefined in descendants as:

[ Top ]
complete_trans  [line 132]

  void complete_trans( )

Finishing transaction


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
connect  [line 80]

  void connect( )

Tries to connect to DB


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
disconnect  [line 87]

  void disconnect( )

Disconnects from the DB


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
execute  [line 147]

  void execute( string $sql, [ $ignore_sql_injection_warning = false]  )

Executes SQL statemnt

Parameters:
string   $sql: 
   $ignore_sql_injection_warning: 

API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
fail_trans  [line 139]

  void fail_trans( )

Manually marking transaction as failed


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
generate_id  [line 177]

  void generate_id( $sequence_name, [unknown_type $start = 1], string $table_id_is_for  )

Generates next id from sequence

For RDBMS that does not support sequences this have to be emulated by DB abstraction layer

Parameters:
string   $table_id_is_for:  name of the sequence
unknown_type   $start:  if sequence is not existing $start will be used as initial value when sequence is automatically created
   $sequence_name: 

API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
get_autocommit  [line 211]

  unknown get_autocommit( )

Gets autocommit mode


API Tags:
Access:  public


[ Top ]
get_conn  [line 249]

  unknown get_conn( )

Returns internal db connection object

This function should be used only if you REALLY need to use DBAL (ADODB, PDO, etc...) specific calls.


API Tags:
Access:  public


[ Top ]
get_dsn  [line 116]

  unknown get_dsn( )

Gets DB DSN


API Tags:
Access:  public


[ Top ]
get_error_msg  [line 184]

  void get_error_msg( )

Returns error message if any


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
is_connected  [line 106]

  boolean is_connected( )

Gets $this->connected


API Tags:
Access:  public


[ Top ]
is_like_sql_injection  [line 263]

  boolean is_like_sql_injection( string $sql  )

Checks if $sql looks like SQL injection attempt

This function will check if there are comments in the $sql and if found will return true. Don't overtrust this to keep you safe - allways check and escape data before sending it as SQL statement to the RDBMS

Parameters:
string   $sql: 

API Tags:
Return:  Returns true if $sql is suspicious
Access:  protected


[ Top ]
query  [line 166]

  void query( string $sql  )

Alias of execute()

Parameters:
string   $sql: 

API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
remove_quoted  [line 302]

  string remove_quoted( string $sql_str  )

Removes quoted content from $sql_str

Parameters:
string   $sql_str: 

API Tags:
Internal:  
Access:  private


[ Top ]
select_limit  [line 159]

  void select_limit( string $sql, integer $num_rows, integer $offset  )

Selects limited ammount of rows

Useful for paginating the results.

Parameters:
string   $sql:  SQL statement
integer   $num_rows:  number of rows to select
integer   $offset:  offset to start

API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
set_autocommit  [line 201]

  void set_autocommit( unknown_type $auto  )

Sets autocommit mode

Parameters:
unknown_type   $auto: 

API Tags:
Access:  public


[ Top ]
set_connected  [line 96]

  void set_connected( boolean $connected  )

Sets $this->connected

Parameters:
boolean   $connected: 

API Tags:
Access:  protected


[ Top ]
start_trans  [line 125]

  void start_trans( )

Starting transaction


API Tags:
Abstract:  
Access:  public


Redefined in descendants as:

[ Top ]
_remove_quoted_with  [line 327]

  string _remove_quoted_with( string $sql_str, string $q  )

Removes quoted with $q from $sql_str

Parameters:
string   $sql_str: 
string   $q:  One character ' or "

API Tags:
Access:  private


[ Top ]