[Talossa.com portal]
[Citizens Toolbox]
[Immigration]
No Running elections
The Typo3 t3lib_DB class(#23), posted by Mr. Furxheir, R.M.W., [IP Hidden], November 23, 2004 - 07:58. Viewed 1017 times.
User InfoText
Mr. Furxheir, R.M.W.
Group: admins
(1791 posts total)
(last post: November 24, 2007 - 15:07)
Citizen #20:
Martí- Paìr Furxhéir
When working with a database, knowledge of the SQL is usually required.

However, Kasper, creator of Typo3 ( which is notably used for Talossa.net and Talossa.info ) has create a simple to use database class, t3lib_DB.

Here is an introduction to the class, to enable people to understand how to use it.

Please note that this is not sufficient to actually do anything, but it is one of the puzzle pieces.

Also, please note that some of the functions only works on Typo3 tables or are not appropriate for the DB, so I removed them.

class t3lib_DB

SECTION: Query execution

//////////////////////////////////////////////////////////////
// This function inserts a new row into the specified table.
//
// The fields_values is an array where the keys are the field names,
// and the values are the actual value names.
//
function exec_INSERTquery($table,$fields_values)

//////////////////////////////////////////////////////////////////
// This function modifies one or more fields on the rows matching
// the where condition in the specified table.
//
// where is a string. It can be ''
//
// The fields_values is an array where the keys are the field names,
// and the values are the actual value names.
//
function exec_UPDATEquery($table,$where,$fields_values)


//////////////////////////////////////////////////////////////////
// This function deletes rows matching the where condition from
// the specified table.
//
// where is a string. It can be ''
//
function exec_DELETEquery($table,$where)


//////////////////////////////////////////////////////////////////
// This function selects ( lists ) the specified fields ( * for all )
// from the rows matching the where condition from the specified table.
// it can groupBy, orderBy or limit the query ( more on that later ).
//
// All of the fields are strings.
//
function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='')

//////////////////////////////////////
// SECTION: Query building
//////////////////////////////////////


//////////////////////////////////////////////////////////////
// This function creates a query that inserts a new row
// into the specified table.
//
// exec_INSERTquery should be used instead.
//
// The fields_values is an array where the keys are the field names,
// and the values are the actual value names.
//
function INSERTquery($table,$fields_values)

//////////////////////////////////////////////////////////////////
// This function creates a query that modifies one or more fields
// on the rows matching the where condition in the specified table.
//
// exec_UPDATEQquery should be called instead.
//
// where is a string. It can be ''
//
// The fields_values is an array where the keys are the field names,
// and the values are the actual value names.
//
function UPDATEquery($table,$where,$fields_values)

//////////////////////////////////////////////////////////////////
// This function creates a query that deletes rows matching the where
// condition from the specified table.
//
// exec_DELETEquery should be used instead
//
// where is a string. It can be ''
//
function DELETEquery($table,$where)

//////////////////////////////////////////////////////////////////
// This function creates a query that selects ( lists ) the specified
// fields ( * for all ) from the rows matching the where condition
// from the specified table. It can groupBy, orderBy or limit the
// query ( more on that later ).
//
// exec_SELECTquery should be called instead.
//
// All of the fields are strings.
//
function SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='')

/////////////////////////////////////////////////////////////////
// The Typo3 documentation says :
/**

* Returns a WHERE clause that can find a value ($value) in a list field ($field)
* For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their positioni in the list (left, middle or right).
* Is nice to look up list-relations to records or files in TYPO3 database tables.
*
* @param string Field name
* @param string Value to find in list
* @param string Table in which we are searching (for DBAL detection of quoteStr() method)
* @return string WHERE clause for a query
*/
function listQuery($field, $value, $table)

///////////////////////////////////////////////////////////////
// The Typo3 documentation says :
/**
* Returns a WHERE clause which will make an AND search for the words in the $searchWords array in any of the fields in array $fields.
*
* @param array Array of search words
* @param array Array of fields
* @param string Table in which we are searching (for DBAL detection of quoteStr() method)
* @return string WHERE clause for search
*/
function searchQuery($searchWords,$fields,$table)

SECTION: MySQL wrapper functions

These function behave just like their Mysql counterparts.

function sql($db,$query)
function sql_query($query)
function sql_error()
function sql_num_rows($res)
function sql_fetch_assoc($res)
function sql_fetch_row($res)
function sql_free_result($res)
function sql_insert_id()
function sql_affected_rows()
function sql_data_seek($res,$seek)
function sql_field_type($res,$pointer)




terrorism, terrorism, the roof is on fire !





Reply to this post | Back to the forum | Forums Overview| Activate Thread View
Forums Overview | Login | Register | Lost your password? Cyphor (Release: 0.19, PHP 5.2.5)