Classes Elements

sqlStorage

public class sqlStorage

SQL Storage Abstraction Layer Class.
Simple wrapper class for SQL.

AuthorsSofterra LLC <contacts@softerra.com>
Version1.5
Copyright© 2000-2001 Softerra LLC

 

Public Method Summary

void

sqlStorage()

Constructor of SQL Storage Class.
string

getServer()

Get SQL server connect to.
void

debugOn()

Turn on a SQL debugger.
void

debugOff()

Turn off a SQL debugger.
void

connect(string $host, string $user, string $password, string $name)

Open a connection to a SQL Server.
void

close()

Close a SQL connection.
void

select_db(string $database)

Select a SQL database.
array

list_dbs()

List databases available on a SQL server .
array

list_tables([ string $database ])

List tables in a SQL database.
array

list_fields(string $table, [ string $database ])

List SQL result fields.
string

error()

Return the text of the error message from previous SQL operation.
integer

free_result()

Free result memory.
integer

query(string $query)

Send a SQL query.
integer

affected_rows()

Get number of affected rows in previous SQL operation.
integer

select(string $tables, [ string $fields, string $conditions ])

Send a SQL SELECT query.
integer

update(string $table, array $values, [ string $conditions ])

Send a SQL UPDATE query.
integer

insert(string $table, array $values)

Send a SQL INSERT query.
integer

delete(string $table, [ string $conditions ])

Send a SQL DELETE query.
integer

result([ integer $row, integer $field ])

Get result data.
integer

num_rows()

Get number of rows in result.
integer

num_fields()

Get number of fields in result.
array

fetch_row()

Get a result row as an enumerated array.
array

fetch_array()

Fetch a result row as an associative array.
Object

fetch_object([ integer $type ])

Fetch a result row as an object.
Object

fetch_field(integer $offset)

Get column information from a result and return as an object .
array

fetch_fields()

Get column information from a result and return as array of objects.
array

fetch_result([ string $format ])

Fetch all rows of result data into an multi-dimensional array.
array

fetch_rows()

Fetch all rows of result data into an multi-dimensional array.
array

fetch_arrays()

Fetch all rows of result data into an multi-dimensional array.
array

fetch_objects()

Fetch all rows of result data.
integer

insert_id()

Get the id generated from the previous INSERT operation.
boolean

queryresult_exists()

Check if the previous SELECT operation returns result data.
integer

queryresult_record()

Fetch next row and return value of the first field.
array

queryresult_column()

Fetch all rows of result data and return values of the first column.
boolean

select_exists(string $tables, [ string $conditions ])

Send a SELECT query and check if result data is not empty.
integer

select_count(string $tables, [ string $conditions ])

Prepare and send a SELECT query to count number of rows for the specified conditions.
integer

select_record(string $tables, string $fields, [ string $conditions ])

Send a SELECT query and return value of the first row and the first field.
array

select_row(string $tables, string $fields, [ string $conditions ])

Send a SELECT query and return the first result row as an associative array.
array

select_column(string $tables, string $fields, [ string $conditions ])

Send a SELECT query and return values of the first column.
array

select_result(string $tables, string $fields, [ string $conditions, string $format ])

Send a SELECT query and return all rows of result data into an multi-dimensional array.
array

search(string $expression, string $table, [ string $field, string $fields, string $type, integer $limit ])

Prepare and send a SELECT query according specified espression.

Private Method Summary

boolean

sal_unsupported_method(string $method)

Print error message.

Private Field Summary

boolean

$debug

Debug flag.
string

$debugmessage

Debug message.
integer

$connection

Connection link ID.
integer

$queryresult

Result data link ID.
integer

$database

DB link ID.
integer

$query_count

Query counter.

Private Constant Summary

_SQLSTORAGE_CLASS_ >>sqlstorage.class.php<< File name.
strErrorConnect >>Fatal: Can't connect to database.\n<< Error message.
strErrorSelect >>Fatal: Can't select from database.\n<< Error message.
fmtRow >>1<< Row format type.
fmtArr >>2<< Array format type.
fmtObj >>3<< Object format type.

Public Method Details

sqlStorage

public void sqlStorage( )

  Constructor of SQL Storage Class.

Returns void


getServer

public string getServer( )

  Get SQL server connect to.

Returns string

Type of the SQL server eg. "MySQL"


debugOn

public void debugOn( )

  Turn on a SQL debugger.

Returns void


debugOff

public void debugOff( )

  Turn off a SQL debugger.

Returns void


connect

public void connect( string $host, string $user, string $password, string $name )

  Open a connection to a SQL Server.
Stop HTML output and display an error message on failure.

Parameter
string $host
The hostname string can also include a port number. eg. "hostname:port".
string $user
User name
string $password
Password
string $name
DB name
Returns void

See Also close()

close

public void close( )

  Close a SQL connection.
This isn't usually necessary, as non-persistent open links are automatically closedat the end of the script's execution.

Returns void

See Also connect()

select_db

public void select_db( string $database )

  Select a SQL database.
Set the current active database on the server.

Parameter
string $database
DB name
Returns void

See Also connect()

list_dbs

public array list_dbs( )

  List databases available on a SQL server .
Return an array of the database names available from the current sql daemon.

Returns array

See Also list_tables(), list_fields()

list_tables

public array list_tables( [ string $database ] )

  List tables in a SQL database.
Take a database name and returns an array of table names.

Parameter
string $database = >>""<<
DB Name
Returns array

See Also list_dbs(), list_fields()

list_fields

public array list_fields( string $table, [ string $database ] )

  List SQL result fields.
Take a table name and returns an array of field names.

Parameter
string $table
Table Name
string $database = >>""<<
DB Name (optional)
Returns array

See Also list_dbs(), list_tables()

error

public string error( )

  Return the text of the error message from previous SQL operation.
Return the empty string if no error occurred.

Returns string


free_result

public integer free_result( )

  Free result memory.
Only need to be called if you are worried about using too much memorywhile your script is running. All associated result memoryfor the specified result identifier will automatically be freed.

Returns integer


query

public integer query( string $query )

  Send a SQL query.
The query string should not end with a semicolon.Return TRUE (non-zero) or FALSE to indicate whether or not the query succeeded.

Parameter
string $query
Returns integer

See Also select(), update(), insert(), delete()

affected_rows

public integer affected_rows( )

  Get number of affected rows in previous SQL operation.
Return the number of rows affected by the last INSERT, UPDATE or DELETE query.If the last query was a DELETE query with no WHERE clause,all of the records will have been deleted from the table but this function will return zero.This method is not effective for SELECT statements, only on statements which modify records.

Returns integer

See Also num_rows()

select

public integer select( string $tables, [ string $fields, string $conditions ] )

  Send a SQL SELECT query.
Return TRUE (non-zero) or FALSE to indicate whether or not the query succeeded.

Parameter
string $tables
Table name(s), can be also an array.
string $fields = >>"*"<<
Field name(s), can be also an array. If no specified select all fields.
string $conditions = >>""<<
Condition, can be also an array.
Returns integer

See Also query(), select_count(), select_exists(), select_record(), select_row(), select_column(), select_result()

update

public integer update( string $table, array $values, [ string $conditions ] )

  Send a SQL UPDATE query.
Return TRUE (non-zero) or FALSE to indicate whether or not the query succeeded.

Parameter
string $table
Table name.
array $values
An associative array contains field name(s) as key(s).
string $conditions = >>""<<
Condition, can be also an array.
Returns integer

See Also query()

insert

public integer insert( string $table, array $values )

  Send a SQL INSERT query.
Return TRUE (non-zero) or FALSE to indicate whether or not the query succeeded.

Parameter
string $table
Table name.
array $values
An associative array contains field name(s) as key(s).
Returns integer

See Also query(), insert_id()

delete

public integer delete( string $table, [ string $conditions ] )

  Send a SQL DELETE query.
Return TRUE (non-zero) or FALSE to indicate whether or not the query succeeded.

Parameter
string $table
Table name.
string $conditions = >>""<<
Condition, can be also an array.
Returns integer

See Also query()

result

public integer result( [ integer $row, integer $field ] )

  Get result data.
Return the contents of one cell from a SQL result set.The field argument can be the field's offset, or the field's name,or the field's table dot field's name (fieldname.tablename).If the column name has been aliased ('select foo as bar from...'),use the alias instead of the column name.

Parameter
integer $row = >>0<<
integer $field = >>0<<
Returns integer

See Also fetch_row(), fetch_array(), fetch_object(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

num_rows

public integer num_rows( )

  Get number of rows in result.
This method is only valid for SELECT statements.

Returns integer

See Also affected_rows(), num_fields()

num_fields

public integer num_fields( )

  Get number of fields in result.
This method is only valid for SELECT statements.

Returns integer

See Also num_rows()

fetch_row

public array fetch_row( )

  Get a result row as an enumerated array.
Fetch one row of data from the result associated with the specified result identifier.The row is returned as an array. Each result column is stored in an array offset,starting at offset 0.

Returns array

See Also result(), fetch_array(), fetch_object(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_array

public array fetch_array( )

  Fetch a result row as an associative array.
In addition to storing the data in the numeric indices of the result array,it also stores the data in associative indices, using the field names as keys.

Returns array

See Also result(), fetch_row(), fetch_object(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_object

public Object fetch_object( [ integer $type ] )

  Fetch a result row as an object.
Return an object with properties that correspond to the fetched row,or false if there are no more rows.

Parameter
integer $type = >>0<<
Returns Object

See Also result(), fetch_row(), fetch_array(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_field

public Object fetch_field( integer $offset )

  Get column information from a result and return as an object .
Can be used in order to obtain information about fields in a certain query result.If the field offset isn't specified, the next field that wasn't yet retrievedby fetch_field() is retrieved.

Parameter
integer $offset
Returns Object

See Also result(), fetch_row(), fetch_array(), fetch_object(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_fields

public array fetch_fields( )

  Get column information from a result and return as array of objects.
Can be used in order to obtain information about fields in a certain query result.

Returns array

See Also result(), fetch_row(), fetch_array(), fetch_object(), fetch_field(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_result

public array fetch_result( [ string $format ] )

  Fetch all rows of result data into an multi-dimensional array.
Return a multi-dimensional array[row][field] or array[row] of objects depending on $format parameter.

Parameter
string $format = >>fmtRow<<
Accept the following constants: fmtRow, fmtArr, fmtObj.
Returns array

See Also result(), fetch_row(), fetch_array(), fetch_object(), fetch_field(), fetch_fields(), fetch_rows(), fetch_arrays(), fetch_objects()

fetch_rows

public array fetch_rows( )

  Fetch all rows of result data into an multi-dimensional array.
Return a multi-dimensional array[row][field].

Returns array

See Also result(), fetch_row(), fetch_array(), fetch_object(), fetch_field(), fetch_fields(), fetch_result(), fetch_arrays(), fetch_objects()

fetch_arrays

public array fetch_arrays( )

  Fetch all rows of result data into an multi-dimensional array.
Return a multi-dimensional array[row][field].

Returns array

See Also result(), fetch_row(), fetch_array(), fetch_object(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_objects()

fetch_objects

public array fetch_objects( )

  Fetch all rows of result data.
Return an array[row] of objects.

Returns array

See Also result(), fetch_row(), fetch_array(), fetch_field(), fetch_fields(), fetch_result(), fetch_rows(), fetch_arrays(), fetch_objects()

insert_id

public integer insert_id( )

  Get the id generated from the previous INSERT operation.
Return the ID generated for an AUTO_INCREMENTED field.

Returns integer

See Also insert()

queryresult_exists

public boolean queryresult_exists( )

  Check if the previous SELECT operation returns result data.
Return TRUE if the previous SELECT operation returns result data.

Returns boolean

See Also queryresult_record(), queryresult_column()

queryresult_record

public integer queryresult_record( )

  Fetch next row and return value of the first field.

Returns integer

See Also queryresult_exists(), queryresult_column()

queryresult_column

public array queryresult_column( )

  Fetch all rows of result data and return values of the first column.

Returns array

See Also queryresult_record(), queryresult_exists()

select_exists

public boolean select_exists( string $tables, [ string $conditions ] )

  Send a SELECT query and check if result data is not empty.

Parameter
string $tables
Table name(s), can be also an array.
string $conditions = >>""<<
Condition, can be also an array.
Returns boolean

See Also select(), select_count(), select_record(), select_row(), select_column(), select_result()

select_count

public integer select_count( string $tables, [ string $conditions ] )

  Prepare and send a SELECT query to count number of rows for the specified conditions.

Parameter
string $tables
Table name(s), can be also an array.
string $conditions = >>""<<
Condition, can be also an array.
Returns integer

See Also select(), select_exists(), select_record(), select_row(), select_column(), select_result()

select_record

public integer select_record( string $tables, string $fields, [ string $conditions ] )

  Send a SELECT query and return value of the first row and the first field.

Parameter
string $tables
Table name(s), can be also an array.
string $fields
Field name(s), can be also an array. If no specified select all fields.
string $conditions = >>""<<
Condition, can be also an array.
Returns integer

See Also select(), select_count(), select_exists(), select_row(), select_column(), select_result()

select_row

public array select_row( string $tables, string $fields, [ string $conditions ] )

  Send a SELECT query and return the first result row as an associative array.

Parameter
string $tables
Table name(s), can be also an array.
string $fields
Field name(s), can be also an array. If no specified select all fields.
string $conditions = >>""<<
Condition, can be also an array.
Returns array

See Also select(), select_count(), select_exists(), select_record(), select_column(), select_result()

select_column

public array select_column( string $tables, string $fields, [ string $conditions ] )

  Send a SELECT query and return values of the first column.

Parameter
string $tables
Table name(s), can be also an array.
string $fields
Field name(s), can be also an array. If no specified select all fields.
string $conditions = >>""<<
Condition, can be also an array.
Returns array

See Also select(), select_count(), select_exists(), select_record(), select_row(), select_result()

select_result

public array select_result( string $tables, string $fields, [ string $conditions, string $format ] )

  Send a SELECT query and return all rows of result data into an multi-dimensional array.

Parameter
string $tables
Table name(s), can be also an array.
string $fields
Field name(s), can be also an array. If no specified select all fields.
string $conditions = >>""<<
Condition, can be also an array.
string $format = >>fmtArr<<
Accept the following constants: fmtRow, fmtArr, fmtObj
Returns array

See Also select(), select_count(), select_exists(), select_record(), select_row(), select_column()

search

public array search( string $expression, string $table, [ string $field, string $fields, string $type, integer $limit ] )

  Prepare and send a SELECT query according specified espression.
Return all rows of result data into an multi-dimensional array.

Parameter
string $expression
Expression.
string $table
Table name.
string $field = >>""<<
Field name.
string $fields = >>"*"<<
Field name(s), can be also an array. If no specified select all fields.
string $type = >>SQL_PATTERN,<<
Accept the following constants: SQL_PATTERN, REGEXP_PATTERN
integer $limit = >>0<<
Limit of result data.
Returns array


Private Method Details

sal_unsupported_method

private boolean sal_unsupported_method( string $method )

  Print error message.

Parameter
string $method
Returns boolean


Private Field Details

$debug

private boolean $debug

>><<

Debug flag.


$debugmessage

private string $debugmessage

>><<

Debug message.


$connection

private integer $connection

>><<

Connection link ID.


$queryresult

private integer $queryresult

>><<

Result data link ID.


$database

private integer $database

>><<

DB link ID.


$query_count

private integer $query_count

>><<

Query counter.


Private Constant Details

_SQLSTORAGE_CLASS_

define( _SQLSTORAGE_CLASS_, >>sqlstorage.class.php<< )
Case: default: case sensitive

File name.


strErrorConnect

define( strErrorConnect, >>Fatal: Can't connect to database.\n<< )
Case: default: case sensitive

Error message.


strErrorSelect

define( strErrorSelect, >>Fatal: Can't select from database.\n<< )
Case: default: case sensitive

Error message.


fmtRow

define( fmtRow, >>1<< )
Case: default: case sensitive

Row format type.


fmtArr

define( fmtArr, >>2<< )
Case: default: case sensitive

Array format type.


fmtObj

define( fmtObj, >>3<< )
Case: default: case sensitive

Object format type.