Lightnote CMS - web 2.0 content management system

API Reference

Overview | API Reference
DB DB( [string/resource $DB_host = null], [string $DB_name = null], [string $DB_user = null], [string $DB_pass = null])

Constuctor, if nothing passed into function will try to get existent MySQL connecton.

Parameters:
string/resource $DB_host - mysql server hostname (or ip address), or mysql link to db (if first parameter is MySQL Link resource, then other three not needed).
string $DB_name - name of database
string $DB_user - username
string $DB_pass - password
bool Connect( )

Makes connection to database.

void Delete( string $tableName, array $whereParams)

Deletes rows from specified table.

Parameters:
string $tableName - name of table
array $whereParams - array with where params (i.e.: array("id"=>20))
resource DoQuery( string $query)

Executes MySQL query and returns MySQL result resource. If MySQL error occurs - outputs query, error and trace information.

Parameters:
string $query - - SQL query
bool FieldExists( string $tableName, string $fieldName)

Checks whether specified field exists in specified table.

Parameters:
string $tableName - table name
string $fieldName - name of filed in table
array GetAllTables( )

Returns an array with tables and their fields

array GetColumn( string $query)

Returns first column from result set as indexed array.

Parameters:
string $query - query string
int GetFoundRows( )

Method is usable after using SQL_CALC_FOUND_ROWS statement in your query. Returns total number of found rows.

array GetRow( string $query)

Returns first row as associative array from result set, if nothing found returns NULL

Parameters:
string $query - query string
array GetRows( string $query)

Returns indexed array of rows returned by MySQL.

Parameters:
string $query - - select query
void GetRowsCount( )

Use this function, if you have used SQL_CALC_FOUND_ROWS and want to obtain how much was found at all

int GetScalar( string $query)

Returns first row, first column from result set, useful for getting scalars (count(), max(), id and so on).

if nothing found returns -1

Parameters:
string $query - - query string
string GetSearchSql( string[] $fields, string $searchString, int $searchType)

Returns WHERE SQL statement based on search string and search fields.

Parameters:
string[] $fields - indexed array with fields to be searched
string $searchString - search string
int $searchType - search type, 0 = At least 1 word, 1 = All words
string GetSimpleWhereSql( string $tableName, array $params)

Returns WHERE statement by specified associative array

Parameters:
string $tableName - - name of table
array $params - - associative array with
string GetValue( string $query)

Returns first row, first column from result

if nothing found, returns null

Parameters:
string $query - query string
int Insert( string $tableName, [array $params = null])

Inserts new row to table and returns insert id, on failure returns -1

Parameters:
string $tableName - name of table
array $params - array in following format: array[string fieldname] = object fieldvalue
array ProfileEnd( $name $name)

End profiler and returns it's result

Parameters:
$name $name - name of profiler
void ProfileStart( string $name)

Starts profiler, profiler is needed to obtain which query takes most of time and how much times each query is executed

Parameters:
string $name - name of profiler (also needed to stop profiler), needed since different profilers can run parallel
int Replace( string $tableName, array $params, array $whereParams)

Similiar to update, if entry doesn't exists, Inserts a new one

Parameters:
string $tableName - name of table
array $params - array in following format: array[string fieldname] = object fieldvalue
array $whereParams - array with where params for example array("id"=>20)
void SaveQueriesToFile( string $filename, [bool $append = false], [string $title = ""])

Saves all executed queries into file.

Parameters:
string $filename - - filename
bool $append - - optional parameter to append or not to file (default false)
string $title - - optional parameter for file header
void SetUtf8( )

Sets names to utf8 (SET NAMES utf8;)

bool TableExists( string $tableName)

Returns true if specified table exists

Parameters:
string $tableName - name of table
void Update( string $tableName, array $params, array $whereParams)

Updates row in a table

Parameters:
string $tableName - name of table
array $params - array in following format: array[string fieldname] = object fieldvalue
array $whereParams - array with where params for example array("id"=>20)