phpDocumentor CoreAPI
DatabaseAPI
[ class tree: CoreAPI ] [ index: CoreAPI ] [ all elements ]

Procedural File: database_api.php

Source Location: /core/database_api.php

Page Details

Database

This is the general interface for all database calls. Modifications required for database support, outside of adodb support should occur here.

Copyright:  Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
Copyright:  Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net
Link:  http://www.mantisbt.org
Usedby:  bug_get_attachments()
Usedby:  bug_set_field()
Usedby:  bug_get_bugnote_stats()
Usedby:  bug_assign()
Usedby:  bug_update_date()
Usedby:  bug_unmonitor()
Usedby:  bug_monitor()
Usedby:  bug_get_newest_bugnote_timestamp()
Usedby:  bug_reopen()
Usedby:  bug_create()
Usedby:  access_api.php
Uses:  gpc_api.php
Uses:  config_api.php
Usedby:  bug_cache_row()
Usedby:  bug_cache_array_rows()
Usedby:  bug_delete_all()
Usedby:  bug_is_overdue()
Usedby:  bug_text_cache_row()
Usedby:  bug_get_bugnote_count()
Includes
require_once ($t_core_dir.'gpc_api.php') [line 37]

requires gpc_api

[ Top ]

require_once ('adodb/adodb.inc.php') [line 41]
[ Top ]


Constants
PLUGINS_DISABLED  [line 1029]

PLUGINS_DISABLED = true

[ Top ]


Globals
bool   $ADODB_FETCH_MODE [line 65]

set adodb fetch mode

Default value:  ADODB_FETCH_ASSOC

[ Top ]

bool   $g_db_connected [line 53]

Stores whether a database connection was succesfully opened.

Default value:  false

[ Top ]

bool   $g_db_log_queries [line 59]

Store whether to log queries ( used for show_queries_count/query list)

Default value:  config_get_global( 'show_queries_count' )

[ Top ]

int   $g_db_param_count [line 71]

Tracks the query parameter count for use with db_aparam().

Default value:  0

[ Top ]

array   $g_queries_array [line 47]

An array in which all executed queries are stored. This is used for profiling

Default value:  array()

[ Top ]


Functions
db_affected_rows  [line 425]

int db_affected_rows( [ADORecordSet $p_result = Database Query Record Set to retrieve affected rows for.]  )

Retrieve number of rows affected by a specific database query

Parameters:
ADORecordSet   $p_result:  Database Query Record Set to retrieve affected rows for.

API Tags:
Return:  Affected Rows


[ Top ]
db_bind_date  [line 749]

string db_bind_date( string|int $p_date  )

prepare a date for binding in the format database accepts.

Parameters:
string|int   $p_date:  can be a Unix integer timestamp or an ISO format Y-m-d. If null or false or '' is passed in, it will be converted to an SQL null.

API Tags:
Return:  Formatted Date for DB insertion e.g. 1970-01-01 ready for database insertion


[ Top ]
db_bind_timestamp  [line 760]

string db_bind_timestamp( string|int $p_date, [bool $p_gmt = false]  )

prepare a date/time for binding in the format database accepts.

Parameters:
string|int   $p_date:  can be a Unix integer timestamp or an ISO format Y-m-d h:m:s. If null or false or '' is passed in, it will be converted to an SQL null.
bool   $p_gmt:  whether to use GMT or current timezone (default false)

API Tags:
Return:  Formatted Date for DB insertion e.g. 1970-01-01 00:00:00 ready for database insertion


[ Top ]
db_check_database_support  [line 148]

bool db_check_database_support( $p_db_type  )

Returns whether php supprot for a database is enabled

Parameters:
   $p_db_type: 

API Tags:
Return:  indicating if php current supports the given database type


[ Top ]
db_close  [line 658]

void db_close( )

close the connection.

Not really necessary most of the time since a connection is automatically closed when a page finishes loading.



[ Top ]
db_connect  [line 84]

bool db_connect( string $p_dsn, [string $p_hostname = null], [string $p_username = null], [string $p_password = null], [string $p_database_name = null], [string $p_db_schema = null], [bool $p_pconnect = false]  )

Open a connection to the database.

Parameters:
string   $p_dsn:  Database connection string ( specified instead of other params)
string   $p_hostname:  Database server hostname
string   $p_username:  database server username
string   $p_password:  database server password
string   $p_database_name:  database name
string   $p_db_schema:  Schema name (only used if database type is DB2)
bool   $p_pconnect:  Use a Persistent connection to database

API Tags:
Return:  indicating if the connection was successful


[ Top ]
db_count_queries  [line 954]

int db_count_queries( )

count queries



[ Top ]
db_count_unique_queries  [line 964]

int db_count_unique_queries( )

count unique queries



[ Top ]
db_date  [line 856]

string db_date( [$p_timestamp $p_timestamp = null], [bool $p_gmt = false]  )

convert unix timestamp to db compatible date

Parameters:
bool   $p_gmt:  whether to use GMT or current timezone (default false)
$p_timestamp   $p_timestamp:  Date

API Tags:
Return:  Formatted Date

Information Tags:
Todo:  review date handling

[ Top ]
db_error  [line 646]

void db_error( [ $p_query = null]  )

send both the error number and error message and query (optional) as paramaters for a triggered error

Parameters:
   $p_query: 

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_error_msg  [line 636]

string db_error_msg( )

Returns the last status or error message. Returns the last status or error message. The error message is reset when Execute() is called.

This can return a string even if no error occurs. In general you do not need to call this function unless an ADOdb function returns false on an error.


API Tags:
Return:  last error string

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_error_num  [line 624]

int db_error_num( )

Returns the last error number. The error number is reset after every call to Execute(). If 0 is returned, no error occurred.


API Tags:
Return:  last error number

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_fetch_array  [line 436]

array db_fetch_array( &$p_result, bool|ADORecordSet $p_result  )

Retrieve the next row returned from a specific database query

Parameters:
bool|ADORecordSet   $p_result:  Database Query Record Set to retrieve next result for.
   &$p_result: 

API Tags:
Return:  Database result


[ Top ]
db_field_exists  [line 604]

bool db_field_exists( string $p_field_name, string $p_table_name  )

Check if the specified field exists in a given table

Parameters:
string   $p_field_name:  a database field name
string   $p_table_name:  a valid database table name

API Tags:
Return:  indicating whether the field exists


[ Top ]
db_field_names  [line 614]

array db_field_names( string $p_table_name  )

Retrieve list of fields for a given table

Parameters:
string   $p_table_name:  a valid database table name

API Tags:
Return:  array of fields on table


[ Top ]
db_get_table  [line 996]

string db_get_table( $p_option  )

get database table name

Parameters:
   $p_option: 

API Tags:
Return:  containing full database table name


[ Top ]
db_get_table_list  [line 1013]

array db_get_table_list( )

get list database tables


API Tags:
Return:  containing table names


[ Top ]
db_helper_compare_days  [line 914]

string db_helper_compare_days( $p_date1_id_or_column $p_date1_id_or_column, $p_date2_id_or_column $p_date2_id_or_column, $p_limitstring $p_limitstring  )

A helper function to compare two dates against a certain number of days

Parameters:
$p_date1_id_or_column   $p_date1_id_or_column: 
$p_date2_id_or_column   $p_date2_id_or_column: 
$p_limitstring   $p_limitstring: 

API Tags:
Return:  returns database query component to compare dates

Information Tags:
Todo:  Check if there is a way to do that using ADODB rather than implementing it here.

[ Top ]
db_helper_like  [line 894]

string db_helper_like( string $p_field_name, [bool $p_case_sensitive = false], int $p_param_id  )

A helper function that generates a case-sensitive or case-insensitive like phrase based on the current db type.

The field name and value are assumed to be safe to insert in a query (i.e. already cleaned).

Parameters:
string   $p_field_name:  The name of the field to filter on.
int   $p_param_id:  An integer pointing to use for a query_bound value that will represent the value that includes the pattern (can include % for wild cards) - not including the quotations.
bool   $p_case_sensitive:  true: case sensitive, false: case insensitive

API Tags:
Return:  returns (field LIKE 'value') OR (field ILIKE 'value')


[ Top ]
db_index_exists  [line 577]

bool db_index_exists( string $p_table_name, string $p_index_name  )

Check if the specified table index exists.

Parameters:
string   $p_table_name:  a valid database table name
string   $p_index_name:  a valid database index name

API Tags:
Return:  indicating whether the index exists


[ Top ]
db_insert_id  [line 530]

int db_insert_id( [string $p_table = null], [ $p_field = "id"]  )

return the last inserted id for a specific database table

Parameters:
string   $p_table:  a valid database table name
   $p_field: 

API Tags:
Return:  last successful insert id


[ Top ]
db_is_connected  [line 138]

bool db_is_connected( )

Returns whether a connection to the database exists


API Tags:
Return:  indicating if the a database connection has been made
Global:  stores $g_db_connected: database connection state


[ Top ]
db_is_db2  [line 232]

bool db_is_db2( )

Checks if the database driver is DB2


API Tags:
Return:  true if db2


[ Top ]
db_is_mssql  [line 216]

bool db_is_mssql( )

Checks if the database driver is MS SQL


API Tags:
Return:  true if postgres


[ Top ]
db_is_mysql  [line 182]

bool db_is_mysql( )

Checks if the database driver is MySQL


API Tags:
Return:  true if mysql


[ Top ]
db_is_pgsql  [line 198]

bool db_is_pgsql( )

Checks if the database driver is PostgreSQL


API Tags:
Return:  true if postgres


[ Top ]
db_minutes_to_hhmm  [line 882]

string db_minutes_to_hhmm( [int $p_min = 0]  )

convert minutes to a time format [h]h:mm

Parameters:
int   $p_min:  integer representing number of minutes

API Tags:
Return:  representing formatted duration string in hh:mm format.


[ Top ]
db_now  [line 807]

string db_now( )

return current timestamp for DB


API Tags:
Return:  Formatted Date for DB insertion e.g. 1970-01-01 00:00:00 ready for database insertion

Information Tags:
Todo:  add param bool $p_gmt whether to use GMT or current timezone (default false)

[ Top ]
db_null_date  [line 871]

string db_null_date( )

return a DB compatible date, representing a unixtime(0) + 1 second. Internally considered a NULL date


API Tags:
Return:  Formatted Date for DB insertion e.g. 1970-01-01 00:00:00 ready for database insertion


[ Top ]
db_num_rows  [line 414]

int db_num_rows( ADORecordSet $p_result  )

Retrieve number of rows returned for a specific database query

Parameters:
ADORecordSet   $p_result:  Database Query Record Set to retrieve record count for.

API Tags:
Return:  Record Count


[ Top ]
db_param  [line 402]

string db_param( )

Generate a string to insert a parameter into a database query string


API Tags:
Return:  'wildcard' matching a paramater in correct ordered format for the current database.


[ Top ]
db_prepare_binary_string  [line 721]

string db_prepare_binary_string( string $p_string  )

prepare a binary string before DB insertion

Parameters:
string   $p_string:  unprepared binary data

API Tags:
Return:  prepared database query string

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_prepare_bool  [line 798]

int db_prepare_bool( $p_bool, boolean $p_boolean  )

prepare a boolean for database insertion.

Parameters:
boolean   $p_boolean:  boolean
   $p_bool: 

API Tags:
Return:  integer representing boolean
Deprecated:  db_query_bound should be used in preference to this function. This function may be removed in 1.2.0 final

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_prepare_double  [line 787]

double db_prepare_double( double $p_double  )

prepare a double for database insertion.

Parameters:
double   $p_double:  double

API Tags:
Return:  double
Deprecated:  db_query_bound should be used in preference to this function. This function may be removed in 1.2.0 final

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_prepare_int  [line 776]

int db_prepare_int( int $p_int  )

prepare a int for database insertion.

Parameters:
int   $p_int:  integer

API Tags:
Return:  integer
Deprecated:  db_query_bound should be used in preference to this function. This function may be removed in 1.2.0 final

Information Tags:
Todo:  Use/Behaviour of this function should be reviewed before 1.2.0 final

[ Top ]
db_prepare_string  [line 670]

string db_prepare_string( string $p_string  )

prepare a string before DB insertion

Parameters:
string   $p_string:  unprepared string

API Tags:
Return:  prepared database query string
Deprecated:  db_query_bound should be used in preference to this function. This function may be removed in 1.2.0 final


[ Top ]
db_query  [line 255]

ADORecordSet|bool db_query( string $p_query, [int $p_limit = -1], [int $p_offset = -1]  )

execute query, requires connection to be opened An error will be triggered if there is a problem executing the query.

Parameters:
string   $p_query:  Query string to execute
int   $p_limit:  Number of results to return
int   $p_offset:  offset query results for paging

API Tags:
Return:  adodb result set or false if the query failed.
Global:  array $g_queries_array: of previous executed queries for profiling
Global:  adodb $g_db: database connection object
Global:  boolean $g_db_log_queries: indicating whether queries array is populated
Deprecated:  db_query_bound should be used in preference to this function. This function will likely be removed in 1.2.0 final


[ Top ]
db_query_bound  [line 307]

ADORecordSet|bool db_query_bound( string $p_query, [array $arr_parms = null], [int $p_limit = -1], [int $p_offset = -1]  )

execute query, requires connection to be opened An error will be triggered if there is a problem executing the query.

Parameters:
string   $p_query:  Parameterlised Query string to execute
array   $arr_parms:  Array of parameters matching $p_query
int   $p_limit:  Number of results to return
int   $p_offset:  offset query results for paging

API Tags:
Return:  adodb result set or false if the query failed.
Global:  array $g_queries_array: of previous executed queries for profiling
Global:  adodb $g_db: database connection object
Global:  boolean $g_db_log_queries: indicating whether queries array is populated


[ Top ]
db_result  [line 505]

mixed db_result( bool|ADORecordSet $p_result, [int $p_index1 = 0], [int $p_index2 = 0]  )

Retrieve a result returned from a specific database query

Parameters:
bool|ADORecordSet   $p_result:  Database Query Record Set to retrieve next result for.
int   $p_index1:  Row to retrieve (optional)
int   $p_index2:  Column to retrieve (optional)

API Tags:
Return:  Database result


[ Top ]
db_table_exists  [line 546]

bool db_table_exists( string $p_table_name  )

Check if the specified table exists.

Parameters:
string   $p_table_name:  a valid database table name

API Tags:
Return:  indicating whether the table exists


[ Top ]
db_timestamp  [line 820]

string db_timestamp( [$p_date $p_date = null], [bool $p_gmt = false]  )

generate a date/time in database format of a date

Parameters:
bool   $p_gmt:  whether to use GMT or current timezone (default false)
$p_date   $p_date:  Date

API Tags:
Return:  Formatted Date for DB insertion e.g. 1970-01-01 00:00:00 ready for database insertion

Information Tags:
Todo:  review date handling

[ Top ]
db_time_queries  [line 982]

int db_time_queries( )

get total time for queries



[ Top ]
db_unixtimestamp  [line 838]

int db_unixtimestamp( [$p_date $p_date = null], [bool $p_gmt = false]  )

generate a integer unixtimestamp of a date

Parameters:
bool   $p_gmt:  whether to use GMT or current timezone (default false)
$p_date   $p_date:  Date

API Tags:
Return:  unix timestamp of a date

Information Tags:
Todo:  review date handling

[ Top ]


Documentation generated on Sun, 05 Apr 2009 23:01:10 +0100 by phpDocumentor 1.4.1