PHP.sql

SQL wrapper class

Summary
SQL wrapper class
Moves the result position pointer to a certain position.
SQL database query execute with database selection
Returns an associative array for the next table row of an SQL result.
Returns the last SERIAL field to be added to a database.
Get number of rows in a result
Execute an SQL query using the current SQL engine
Determine if any results were generated from the specified query
Moves the result position pointer to a certain position.
SQL query wrapper for creating an SQL table definition
SQL query wrapper for dropping a table
SQL query wrapper for SQL INSERT command
SQL query wrapper for SQL UPDATE command
SQL query wrapper for simple SELECT queries
SQL wrapper for field number count
Produce a list of distinct values for an SQL table field

Functions

sql constructor

Parameters

$typeType of database backend to use.  These are the SQL_ macros defined in macros.php
$options(optional) Associative array of additional options
  • verbose - Set verbosity (boolean)
  • serialize - ‘squash’ or ‘serialize’.  Defaults to squash
  • host - Host computer name
  • user - Username for database server
  • password - Password for database server
  • database - Select database to use
  • path - (only for SQL_SQLLITE) Set path to SQL store

data_seek

function data_seek ($result,
$pos)

Moves the result position pointer to a certain position.  This is just a wrapper for sql->seek

Parameters

$resultSQL result (as returned by sql->query
$posPosition to move to

db_query

function db_query ($database,
$query)

SQL database query execute with database selection

Parameters

$databaseDatabase to select
$querySQL query string

Returns

SQL result

fetch_array

function fetch_array ($result)

Returns an associative array for the next table row of an SQL result.  Functions identically to mysql_fetch_array.

Parameters

$resultSQL result

Returns

Associative array.

last_record

function last_record ($result =  NULL,
$table =  NULL)

Returns the last SERIAL field to be added to a database.  A result and/or table name may be needed, depending on the database engine that is being used.

Parameters

$result(optionally needed) SQL result (from an sql->query call)
$table(optionally needed) Database table name

Returns

Integer, value of last SERIAL column set.

num_rows

function num_rows ($result)

Get number of rows in a result

Parameters

$resultSQL query result reference (as returned by sql->query

Returns

Integer, number of rows in a result

query

function query ($query)

Execute an SQL query using the current SQL engine

Parameters

$queryText of SQL query

Returns

SQL result reference

results

function results ($result)

Determine if any results were generated from the specified query

Parameters

$resultSQL query result (as generated by sql->query

Returns

Boolean, whether there are any results

seek

function seek ($result,
$pos)

Moves the result position pointer to a certain position.

Parameters

$resultSQL result (as returned by sql->query
$posPosition to move to

create_table_query

function create_table_query ($table,  
$values,  
$keys = NULL)

SQL query wrapper for creating an SQL table definition

Parameters

$tableName of table
$valuesAssociative array describing the table definition
$keys(optional) Array of keys.  The first entry is considered the table’s primary key.

Returns

SQL table definition query text

drop_table_query

function drop_table_query ($table)

SQL query wrapper for dropping a table

Parameters

$tableName of table

Returns

SQL query text

insert_query

function insert_query ($table,
$values)

SQL query wrapper for SQL INSERT command

Parameters

$tableName of table
$valuesAssociative array of values to insert into the specified table.  Keys are the table column names and values are the values to be inserted into the table.  Arrays and values with special SQL characters are handled properly.

Returns

SQL query text

update_query

function update_query ($table,
$values,
$where_var)

SQL query wrapper for SQL UPDATE command

Parameters

$tableName of table
$valuesAssociative array of values to update in the specified table.  Keys are the table column names and values are the values to be updated in the table.  Arrays and values with special SQL characters are handled properly.
$where_varAssociative array of WHERE clause conditions for the table update.  These are in the form of key = value.

Returns

SQL query text

select_record_query

function select_record_query ($table,  
$criteria,  
$fields = NULL)

SQL query wrapper for simple SELECT queries

Parameters

$tableName of the table
$criteriaAssociative array of selection crieria.  This is in the form of key = value.
$fields(optional) Array of fields to select.  Defaults to all.

Returns

SQL query text

num_fields

function num_fields ($res)

SQL wrapper for field number count

distinct_values

function distinct_values ($table,  
$field,  
$where =  NULL)

Produce a list of distinct values for an SQL table field

Parameters

$tableName of the SQL table
$fieldName of the SQL field
$where(optional) Where clause contents, if any.  Example would be “msgid=3” or “id=10 AND patient=12”.

Returns

Array of distinct values for the selected field

function data_seek ($result,
$pos)
Moves the result position pointer to a certain position.
function db_query ($database,
$query)
SQL database query execute with database selection
function fetch_array ($result)
Returns an associative array for the next table row of an SQL result.
function last_record ($result =  NULL,
$table =  NULL)
Returns the last SERIAL field to be added to a database.
function num_rows ($result)
Get number of rows in a result
function query ($query)
Execute an SQL query using the current SQL engine
function results ($result)
Determine if any results were generated from the specified query
function seek ($result,
$pos)
Moves the result position pointer to a certain position.
function create_table_query ($table,  
$values,  
$keys = NULL)
SQL query wrapper for creating an SQL table definition
function drop_table_query ($table)
SQL query wrapper for dropping a table
function insert_query ($table,
$values)
SQL query wrapper for SQL INSERT command
function update_query ($table,
$values,
$where_var)
SQL query wrapper for SQL UPDATE command
function select_record_query ($table,  
$criteria,  
$fields = NULL)
SQL query wrapper for simple SELECT queries
function num_fields ($res)
SQL wrapper for field number count
function distinct_values ($table,  
$field,  
$where =  NULL)
Produce a list of distinct values for an SQL table field