Public Method Details |
dal |
public void dal( )
|
|
db_connect constructor function
stores all necessary information in local variables
|
Returns |
void |
|
runsql |
public mixed runsql( string $table, string $sql )
|
|
Sends an SQL string to the database.
|
Parameter |
|
string |
$table |
|
|
Specifies table to run the query on. This is used to
specify the connection data |
|
|
|
Returns |
mixed The resource id of the sql or the return value of any sql
statement |
|
getnextrow |
public array getnextrow( string $table )
|
|
Fetches the next row from a resultset.
The Result identifier is read from the table definitions, where ithas been stored by runsql.
|
Parameter |
|
string |
$table |
|
|
Table to use. This is used to read the result identifier |
|
Returns |
array One row of the resultset with all fields |
|
insert |
public string insert( string $table, array &$row )
|
|
Inserts a record into a table based on database definitions.
Builds an SQL INSERT string from the database definition known to theclass and fills the values from an associative array. Values can bedefined in the db definitions (fields->field->datatype) asint: will be casted to int dec: will be casted to float else: will be quoted and put in quotes. A value 'NULL' will be inserted as NULL.
Also supports a creation timestamp which is prepared by the functionts_srv2utc.
Also supports dbignore (fields->field->dbignore => "yes"), whichlets the function ignore the field.
Returns a possible new autonumber entry.
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
|
array |
&$row |
|
|
@$row Associative array with the field names as keys
and the array-values as values to be inserted |
|
Returns |
string The quoted string |
|
update |
public string update( string $table, array &$row )
|
|
Updates a record into a table based on database definitions.
Builds an SQL UPDATE string from the database definition known to theclass and fills the values from an associative array. Values can bedefined in the db definitions (fields->field->datatype) asint: will be casted to int dec: will be casted to float else: will be quoted and put in quotes. A value 'NULL' will be inserted as NULL.
Fields can also be filled with an array with one value, which willbe directly inserted into the update string. This can be used forthings like <pre>update x set y = y + 2</pre>Also supports an update timestamp which is prepared by the functionts_srv2utc.
Also supports dbignore (fields->field->dbignore => "yes"), whichlets the function ignore the field.
Returns the number of rows affected.
|
Parameter |
|
string |
$table |
|
|
(as defined in db definition) |
|
|
array |
&$row |
|
|
array with the field names as keys
and the array-values as values to be inserted |
|
Returns |
string The quoted string |
|
delete |
public string delete( string $table, string $key )
|
|
Deletes a record from a table based on database definitions.
Deletes a record from a table by using the primary key specified inthe db definitions. If the key is specified as a combined key theparameter must be an ass. array with the key fields as keys and thekey values as array values.
Returns the number of rows affected.
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
|
string |
$key |
|
|
/array $key value of the primary key or
associative array with the values of the
primary key fields to be deleted. |
|
Returns |
string Number of rows affected |
|
count |
public string count( string $table, [ string $appendwhere, integer $use_select_view ] )
|
|
Runs a count(*) statement on a table.
Runs a select count(*) from table statement. There is an optionalargument for a where clause.
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
|
string |
$appendwhere |
= >>""<< |
|
a where clause which reduces the
counted resultset. |
|
|
integer |
$use_select_view |
= >>0<< |
|
1, if the alternative select
table should be used, instead of the normal table. |
|
Returns |
string The number of rows counted, including NULLs |
|
pack_field_value |
public string pack_field_value( string $table, string $fieldname, string $val )
|
|
Pack a field into quotes or not.
Checks for the data type of a field and packs it in quotes if applicable.Also, looks if the value of sqlpackage has been set and packs the field with it.
|
Parameter |
|
string |
$table |
|
|
Table to use |
|
|
string |
$fieldname |
|
|
Name of the field |
|
|
string |
$val |
|
|
Value of the field |
|
Returns |
string |
|
pack_field_name |
public string pack_field_name( string $table, string $usedtblname, string $fieldname )
|
|
Pack a fieldname.
Checks for a table prefix and adds it to the field. Uses the table name to preceedthe field.Also, looks if the value of sqlpackage has been set and packs the field with it.
|
Parameter |
|
string |
$table |
|
|
Table to use |
|
|
string |
$usedtblname |
|
|
Effective tablename to preceed the field |
|
|
string |
$fieldname |
|
|
Name of the field |
|
Returns |
string |
|
assemble_where |
public string assemble_where( string $table, string $op, array $val )
|
|
Assemble a where statement
Assembles a where statement for a list of fields
|
Parameter |
|
string |
$table |
|
|
Table to use |
|
|
string |
$op |
|
|
String, that represents the operator |
|
|
array |
$val |
|
|
Value of each field. This is an associative
array that uses the field names as a key. |
|
Returns |
string the SQL where string |
|
build_column_list |
public array build_column_list( string $table )
|
|
Runs a select statement on a single table or view.
Runs a select statement against a database table or view. Analternative view can be specified for fetch_restricted only.At leastthe where part must be specified. Optionally, an order by clause canbe specified.Additionally supports a limit-statement with SQL Server which isbased on a three times nested subquery. This is very slow with largeresultsets - use a selective where statement.
Also supports dbignore (fields->field->dbignore => "yes"), whichlets the function ignore the field.
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
Returns |
array (ass.array) The resultset as an array of
associative arrays. |
|
fetch |
public array fetch( string $table, [ string $lpk ] )
|
|
Runs a simplified select statement on a single table or view.
Runs a select statement against a database table or view. If nothingis specified there is no where clause used.
Also the order by clause is filled from the "sort_order" fieldin the database definitions. This has to be an array of fieldnames to specify the order. Specify "fieldname desc" for descendingorder.Also supports dbignore (fields->field->dbignore => "yes"), whichlets the function ignore the field.
Internally calls fetch_restricted()
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
|
string |
$lpk |
= >>""<< |
|
/array $lpk a primary key value to specify one
row in the resultset |
|
Returns |
array /array(ass.array) The resultset as an array of
associative arrays (for multiple rows)
or as an associative array (for one row). |
See Also |
fetch_restricted() |
|
ns_fetch_restricted |
public array ns_fetch_restricted( string $table, string $root_id, [ string $where, integer $use_select_view ] )
|
|
Runs a nested set query on a table
The nested set table must be based on numberic fields definingthe nesting and a root id, which can be of any type. The fieldsare defined by the definitions "nsl", "nsr", "nsrid"The function will deliver the whole tree, but further where conditionscan be defined with the where clause. It might probably be best to usethe Alias table "ns2" of the self reference to define any restrictionson the resultset.Also supports dbignore (fields->field->dbignore => "yes"), whichlets the function ignore the field.
Internally calls fetch_restricted()
|
Parameter |
|
string |
$table |
|
|
Tablename (as defined in db definition) |
|
|
string |
$root_id |
|
|
The root id of the tree. |
|
|
string |
$where |
= >>""<< |
|
where-clause to restrict recordset |
|
|
integer |
$use_select_view |
= >>0<< |
|
1, if the alternative select
table should be used, instead of the normal table. |
|
Returns |
array /array(ass.array) The resultset as an array of
associative arrays (for multiple rows)
or as an associative array (for one row). |
|
bot |
public void bot( string $table )
|
|
Starts a transaction
This is only a simple transaction handling yet.
|
Parameter |
|
string |
$table |
|
|
Table to run the transaction on. Used for connection data. |
|
Returns |
void |
See Also |
commit(), rollback() |
|
commit |
public void commit( string $table )
|
|
Commits a transaction
This is only a simple transaction handling yet.
|
Parameter |
|
string |
$table |
|
|
Table to run the transaction on. Used for connection data. |
|
Returns |
void |
See Also |
bot(), rollback() |
|
rollback |
public void rollback( string $table )
|
|
Rolls back a transaction
This is only a simple transaction handling yet.
|
Parameter |
|
string |
$table |
|
|
Table to run the transaction on. Used for connection data. |
|
Returns |
void |
See Also |
bot(), commit() |
|
block_sql_inject |
public void block_sql_inject( mixed &$mixed )
|
|
Blocks SQL injection attacks
This is done (primitively) by cutting of all date from the parameter, which isafter the first ";". Don't use it on data, which contains an ;. The function isapplied recursively on all elements of an array, normal or associative.
|
Parameter |
|
mixed |
&$mixed |
|
|
parameter to secure |
|
Returns |
void |
|
debug_notice |
public void debug_notice( string $sql, string $type )
|
|
Handles printing of SQL statements for debugging
Depending on several constants, this is used internally by theselect, insert, update, count, delete functions. It can also be used toadd sql debugging for routines that build their sql statements themselves.In can then be switched on or off by the appropriate constants
|
Parameter |
|
string |
$sql |
|
|
SQL string to print out |
|
|
string |
$type |
|
|
Type to check the constants for. Can be select,
update, delete, insert or default value is used |
|
Returns |
void |
|