glFusion Wiki

Site Tools


glfusion:development:api:db:functions

Database Functions

The high level database functions for glFusion. These functions are defined in lib-database.php which is always included by glFusion.

DB_affectedRows

(glFusion v1.0.0)

int DB_affectedRows( object $recordset)

Retrieves returns the number of effected rows for last query

Parameters

object $recordset The recordset to operate on

Return

Number of rows affected by previously executed query

DB_change

(glFusion v1.0.0)

void DB_change( string $table, string $item_to_set, string $value_to_set, [array|string $id = ''], [array|string $value = ''], [string $return_page = ''], [boolean $supress_quotes = false])

Changes records in a table

This will change the data in the given table that meet the given criteria and will redirect user to another page if told to do so

Parameters

string $table Table to perform change on
string $item_to_set field name to set
string $value_to_set Value to set abovle field to
array|string $id field name(s) to use in where clause
array|string $value Value(s) to use in where clause
string $return_page page to send user to when done with change
boolean $supress_quotes whether or not to use single quotes in where clause

DB_checkTableExists

(glFusion v1.0.0)

boolean DB_checkTableExists( string $table)

Check if a table exists

Parameters

string $table Table name

Return

True if table exists, false if it does not

DB_copy

(glFusion v1.0.0)

void DB_copy( string $table, string $fields, string $values, string $tablefrom, array|string $id, array|string $value, [string $return_page = ''])

Copies a record from one table to another (can be the same table)

This will use a REPLACE INTO…SELECT FROM to copy a record from one table to another table. They can be the same table.

Parameters

string $table Table to insert record into
string $fields Comma delmited list of fields to copy over
string $values Values to store in database field
string $tablefrom Table to get record from
array|string $id Field name(s) to use in where clause
array|string $value Value(s) to use in where clause
string $return_page Page to send user to when done

DB_count

(glFusion v1.0.0

int DB_count( string $table, [array|string $id = ''], [array|string $value = ''])

Count records in a table

This will return the number of records which meet the given criteria in the given table.

Parameters

string $table Table to perform count on
array|string $id field name(s) to use in where clause
array|string $value Value(s) to use in where clause

Return

Returns row count from generated SQL

DB_createDatabaseStructures

(glFusion v1.0.0)

boolean DB_createDatabaseStructures( )

Creates database structures for fresh installation

This may not be used by glFusion currently

Return

Returns true on success otherwise false

DB_delete

(glFusion v1.0.0)

void DB_delete( string $table, array|string $id, array|string $value, [string $return_page = ''])

Deletes data from the database

This will delete some data from the given table where id = value

Parameters

string $table Table to delete data from
array|string $id field name(s) to use in where clause
array|string $value value(s) to use in where clause
string $return_page page to send user to when done

DB_displayError

(glFusion v1.0.0)

void DB_displayError( boolean $flag)

Setting this on will return the SQL error message.

Default is to not display or return the SQL error but to record it in the error.log file

Parameters

boolean $flag true or false

DB_doDatabaseUpgrade

(glFusion v1.0.0)

boolean DB_doDatabaseUpgrade( string $current_glFusion_version)

Executes the sql upgrade script(s)

Parameters

string $current_glFusion_version version of glFusion to upgrade from

Return

return: returns true on success otherwise false

DB_error

(glFusion v1.0.0)

string DB_error( )

Returns an database error message

Return

Returns database error message

DB_fetchArray

(glFusion v1.0.0)

Array DB_fetchArray( object $recordset, [boolean $both = true])

Retrieves record from a recordset

Gets the next record in a recordset and returns in array

Parameters

object $recordset The recordset to operate on
boolean $both get both assoc and numeric indices

Return

Returns data for a record in an array

DB_fieldName

(glFusion v1.0.0)

string DB_fieldName( object $recordset, int $fnumber)

Returns the field name for a given field number

Parameters

object $recordset The recordset to operate on
int $fnumber field number to return the name of

Return

return: Returns name of specified field

DB_getItem

(glFusion v1.0.0)

mixed DB_getItem( string $table, string $what, [string $selection = ''])

Gets a single item from the database

Parameters

string $table Table to get item from
string $what field name to get
string $selection Where clause to use in SQL

Return

Returns value sought

DB_insertId

(glFusion v1.0.0)

int DB_insertId( [resources $link_identifier = ''])

Returns the last ID inserted

Returns the last auto_increment ID generated

Parameters

resources $link_identifier identifier for opened link

Return

Returns the last ID auto-generated

DB_lockTable

(glFusion v1.0.0)

void DB_lockTable( string $table)

Locks a table for write operations

Parameters

string $table Table to lock

See Also

DB_unlockTable()

DB_numFields

(glFusion v1.0.0)

int DB_numFields( object $recordset)

Retrieves the number of fields in a recordset

Parameters

object $recordset The recordset to operate on

Return

Returns the number fields in a result set

DB_numRows

(glFusion v1.0.0)

int DB_numRows( object $recordset)

Retrieves the number of rows in a recordset

Parameters

object $recordset The recordset to operate one

Return

Returns number of rows returned by a previously executed query

DB_query

(glFusion v1.0.0)

object Returns DB_query( mixed $sql, [int $ignore_errors = 0])

This executes the passed SQL and returns the recordset or errors out

Parameters

mixed $sql String or array of strings of SQL to be executed
int $ignore_errors If 1 this function supresses any error messages

Return

Results from query

DB_result

(glFusion v1.0.0)

(depends DB_result( object $recordset, int $row, string $field)

Retrieves the contents of a field

Parameters

object $recordset The recordset to operate on
int $row row to get data from
string $field field to return

Return

This returns the contents of a field from a result set

DB_save

(glFusion v1.0.0)

void DB_save( string $table, string $fields, string $values, [string $return_page = ''])

Saves information to the database

This will use a REPLACE INTO to save a record into the database. NOTE: this function is going to change in the near future to remove dependency of REPLACE INTO. Please use DB_query if you can

Parameters

string $table The table to save to
string $fields Comma demlimited list of fields to save
string $values Values to save to the database table
string $return_page URL to send user to when done

DB_setDebug

(glFusion v1.0.0)

void DB_setDebug( boolean $flag)

Turns debug mode on for the database library

Setting this to true will cause the database code to print out various debug messages. Setting it to false will supress the messages (is false by default). NOTE: Gl developers have put many useful debug messages into the mysql implementation of this. If you are using something other than MySQL and if the GL team did not write it then you may or may not get something useful by turning this on.

Parameters

boolean $flag true or false

DB_unlockTable

(glFusion v1.0.0)

void DB_unlockTable( string $table)

Unlocks a table after DB_lockTable

Parameters

string $table Table to unlock

See Also

DB_lockTable()

glfusion/development/api/db/functions.txt · Last modified: 2017/04/12 21:15 (external edit)

Page Tools