| [ Index ] |
|
Code source de Typo3 4.1.3 |
[Code source] [Imprimer] [Statistiques]
Contains the class "t3lib_db" containing functions for building SQL queries and mysql wrappers, thus providing a foundational API to all database interaction. This class is instantiated globally as $TYPO3_DB in TYPO3 scripts. $Id: class.t3lib_db.php 2443 2007-08-10 14:37:32Z mundaun $
| Author: | Kasper Skaarhoj <kasperYYYY@typo3.com> |
| Poids: | 1139 lignes (40 kb) |
| Inclus ou requis: | 1 fois |
| Référencé: | 0 fois |
| Nécessite: | 0 fichiers |
t3lib_DB:: (43 méthodes):
exec_INSERTquery()
exec_UPDATEquery()
exec_DELETEquery()
exec_SELECTquery()
exec_SELECT_mm_query()
exec_SELECT_queryArray()
exec_SELECTgetRows()
INSERTquery()
UPDATEquery()
DELETEquery()
SELECTquery()
listQuery()
searchQuery()
fullQuoteStr()
fullQuoteArray()
quoteStr()
escapeStrForLike()
cleanIntArray()
cleanIntList()
stripOrderBy()
stripGroupBy()
splitGroupOrderLimit()
sql()
sql_query()
sql_error()
sql_num_rows()
sql_fetch_assoc()
sql_fetch_row()
sql_free_result()
sql_insert_id()
sql_affected_rows()
sql_data_seek()
sql_field_type()
sql_pconnect()
sql_select_db()
admin_get_dbs()
admin_get_tables()
admin_get_fields()
admin_get_keys()
admin_query()
connectDB()
debug()
debug_check_recordset()
| exec_INSERTquery($table,$fields_values,$no_quote_fields=FALSE) X-Ref |
| Creates and executes an INSERT SQL-statement for $table from the array with field/value pairs $fields_values. Using this function specifically allows us to handle BLOB and CLOB fields depending on DB Usage count/core: 47 param: string Table name param: array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$insertFields" with 'fieldname'=>'value' and pass it to this function as argument. param: string/array See fullQuoteArray() return: pointer MySQL result pointer / DBAL object |
| exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) X-Ref |
| Creates and executes an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. Using this function specifically allow us to handle BLOB and CLOB fields depending on DB Usage count/core: 50 param: string Database tablename param: string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! param: array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$updateFields" with 'fieldname'=>'value' and pass it to this function as argument. param: string/array See fullQuoteArray() return: pointer MySQL result pointer / DBAL object |
| exec_DELETEquery($table,$where) X-Ref |
| Creates and executes a DELETE SQL-statement for $table where $where-clause Usage count/core: 40 param: string Database tablename param: string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! return: pointer MySQL result pointer / DBAL object |
| exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') X-Ref |
| Creates and executes a SELECT SQL-statement Using this function specifically allow us to handle the LIMIT feature independently of DB. Usage count/core: 340 param: string List of fields to select from the table. This is what comes right after "SELECT ...". Required value. param: string Table(s) from which to select. This is what comes right after "FROM ...". Required value. param: string Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! param: string Optional GROUP BY field(s), if none, supply blank string. param: string Optional ORDER BY field(s), if none, supply blank string. param: string Optional LIMIT value ([begin,]max), if none, supply blank string. return: pointer MySQL result pointer / DBAL object |
| exec_SELECT_mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') X-Ref |
| Creates and executes a SELECT query, selecting fields ($select) from two/three tables joined Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $TCA in Inside TYPO3 for more details. Usage: 12 (spec. ext. sys_action, sys_messages, sys_todos) param: string Field list for SELECT param: string Tablename, local table param: string Tablename, relation table param: string Tablename, foreign table param: string Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! You have to prepend 'AND ' to this parameter yourself! param: string Optional GROUP BY field(s), if none, supply blank string. param: string Optional ORDER BY field(s), if none, supply blank string. param: string Optional LIMIT value ([begin,]max), if none, supply blank string. return: pointer MySQL result pointer / DBAL object |
| exec_SELECT_queryArray($queryParts) X-Ref |
| Executes a select based on input query parts array Usage: 9 param: array Query parts array return: pointer MySQL select result pointer / DBAL object |
| exec_SELECTgetRows($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='',$uidIndexField='') X-Ref |
| Creates and executes a SELECT SQL-statement AND traverse result set and returns array with records in. param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string If set, the result array will carry this field names value as index. Requires that field to be selected of course! return: array Array of rows. |
| INSERTquery($table,$fields_values,$no_quote_fields=FALSE) X-Ref |
| Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values. Usage count/core: 4 param: string See exec_INSERTquery() param: array See exec_INSERTquery() param: string/array See fullQuoteArray() return: string Full SQL query for INSERT (unless $fields_values does not contain any elements in which case it will be false) |
| UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) X-Ref |
| Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. Usage count/core: 6 param: string See exec_UPDATEquery() param: string See exec_UPDATEquery() param: array See exec_UPDATEquery() param: array See fullQuoteArray() return: string Full SQL query for UPDATE (unless $fields_values does not contain any elements in which case it will be false) |
| DELETEquery($table,$where) X-Ref |
| Creates a DELETE SQL-statement for $table where $where-clause Usage count/core: 3 param: string See exec_DELETEquery() param: string See exec_DELETEquery() return: string Full SQL query for DELETE |
| SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') X-Ref |
| Creates a SELECT SQL-statement Usage count/core: 11 param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() param: string See exec_SELECTquery() return: string Full SQL query for SELECT |
| listQuery($field, $value, $table) X-Ref |
| 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 |
| searchQuery($searchWords,$fields,$table) X-Ref |
| 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 |
| fullQuoteStr($str, $table) X-Ref |
| Escaping and quoting values for SQL statements. Usage count/core: 100 param: string Input string param: string Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). return: string Output string; Wrapped in single quotes and quotes in the string (" / ') and \ will be backslashed (or otherwise based on DBAL handler) |
| fullQuoteArray($arr, $table, $noQuote=FALSE) X-Ref |
| Will fullquote all values in the one-dimensional array so they are ready to "implode" for an sql query. param: array Array with values (either associative or non-associative array) param: string Table name for which to quote param: string/array List/array of keys NOT to quote (eg. SQL functions) - ONLY for associative arrays return: array The input array with the values quoted |
| quoteStr($str, $table) X-Ref |
| Substitution for PHP function "addslashes()" Use this function instead of the PHP addslashes() function when you build queries - this will prepare your code for DBAL. NOTICE: You must wrap the output of this function in SINGLE QUOTES to be DBAL compatible. Unless you have to apply the single quotes yourself you should rather use ->fullQuoteStr()! Usage count/core: 20 param: string Input string param: string Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). return: string Output string; Quotes (" / ') and \ will be backslashed (or otherwise based on DBAL handler) |
| escapeStrForLike($str, $table) X-Ref |
| Escaping values for SQL LIKE statements. param: string Input string param: string Table name for which to escape string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). return: string Output string; % and _ will be escaped with \ (or otherwise based on DBAL handler) |
| cleanIntArray($arr) X-Ref |
| Will convert all values in the one-dimensional array to integers. Useful when you want to make sure an array contains only integers before imploding them in a select-list. Usage count/core: 7 param: array Array with values return: array The input array with all values passed through intval() |
| cleanIntList($list) X-Ref |
| Will force all entries in the input comma list to integers Useful when you want to make sure a commalist of supposed integers really contain only integers; You want to know that when you don't trust content that could go into an SQL statement. Usage count/core: 6 param: string List of comma-separated values which should be integers return: string The input list but with every value passed through intval() |
| stripOrderBy($str) X-Ref |
| Removes the prefix "ORDER BY" from the input string. This function is used when you call the exec_SELECTquery() function and want to pass the ORDER BY parameter by can't guarantee that "ORDER BY" is not prefixed. Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result. Usage count/core: 11 param: string eg. "ORDER BY title, uid" return: string eg. "title, uid" |
| stripGroupBy($str) X-Ref |
| Removes the prefix "GROUP BY" from the input string. This function is used when you call the SELECTquery() function and want to pass the GROUP BY parameter by can't guarantee that "GROUP BY" is not prefixed. Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result. Usage count/core: 1 param: string eg. "GROUP BY title, uid" return: string eg. "title, uid" |
| splitGroupOrderLimit($str) X-Ref |
| Takes the last part of a query, eg. "... uid=123 GROUP BY title ORDER BY title LIMIT 5,2" and splits each part into a table (WHERE, GROUPBY, ORDERBY, LIMIT) Work-around function for use where you know some userdefined end to an SQL clause is supplied and you need to separate these factors. Usage count/core: 13 param: string Input string return: array |
| sql($db,$query) X-Ref |
| Executes query mysql() wrapper function DEPRECATED - use exec_* functions from this class instead! Usage count/core: 9 param: string Database name param: string Query to execute return: pointer Result pointer / DBAL object |
| sql_query($query) X-Ref |
| Executes query mysql_query() wrapper function Usage count/core: 1 param: string Query to execute return: pointer Result pointer / DBAL object |
| sql_error() X-Ref |
| Returns the error status on the last sql() execution mysql_error() wrapper function Usage count/core: 32 return: string MySQL error string. |
| sql_num_rows($res) X-Ref |
| Returns the number of selected rows. mysql_num_rows() wrapper function Usage count/core: 85 param: pointer MySQL result pointer (of SELECT query) / DBAL object return: integer Number of resulting rows. |
| sql_fetch_assoc($res) X-Ref |
| Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. mysql_fetch_assoc() wrapper function Usage count/core: 307 param: pointer MySQL result pointer (of SELECT query) / DBAL object return: array Associative array of result row. |
| sql_fetch_row($res) X-Ref |
| Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. The array contains the values in numerical indices. mysql_fetch_row() wrapper function Usage count/core: 56 param: pointer MySQL result pointer (of SELECT query) / DBAL object return: array Array with result rows. |
| sql_free_result($res) X-Ref |
| Free result memory mysql_free_result() wrapper function Usage count/core: 3 param: pointer MySQL result pointer to free / DBAL object return: boolean Returns TRUE on success or FALSE on failure. |
| sql_insert_id() X-Ref |
| Get the ID generated from the previous INSERT operation mysql_insert_id() wrapper function Usage count/core: 13 return: integer The uid of the last inserted record. |
| sql_affected_rows() X-Ref |
| Returns the number of rows affected by the last INSERT, UPDATE or DELETE query mysql_affected_rows() wrapper function Usage count/core: 1 return: integer Number of rows affected by last query |
| sql_data_seek($res,$seek) X-Ref |
| Move internal result pointer mysql_data_seek() wrapper function Usage count/core: 3 param: pointer MySQL result pointer (of SELECT query) / DBAL object param: integer Seek result number. return: boolean Returns TRUE on success or FALSE on failure. |
| sql_field_type($res,$pointer) X-Ref |
| Get the type of the specified field in a result mysql_field_type() wrapper function Usage count/core: 2 param: pointer MySQL result pointer (of SELECT query) / DBAL object param: integer Field index. return: string Returns the name of the specified field index |
| sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password) X-Ref |
| Open a (persistent) connection to a MySQL server mysql_pconnect() wrapper function Usage count/core: 12 param: string Database host IP/domain param: string Username to connect with. param: string Password to connect with. return: pointer Returns a positive MySQL persistent link identifier on success, or FALSE on error. |
| sql_select_db($TYPO3_db) X-Ref |
| Select a MySQL database mysql_select_db() wrapper function Usage count/core: 8 param: string Database to connect to. return: boolean Returns TRUE on success or FALSE on failure. |
| admin_get_dbs() X-Ref |
| Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database. This is only used as a service function in the (1-2-3 process) of the Install Tool. In any case a lookup should be done in the _DEFAULT handler DBMS then. Use in Install Tool only! Usage count/core: 1 return: array Each entry represents a database name |
| admin_get_tables() X-Ref |
| Returns the list of tables from the default database, TYPO3_db (quering the DBMS) In a DBAL this method should 1) look up all tables from the DBMS of the _DEFAULT handler and then 2) add all tables *configured* to be managed by other handlers Usage count/core: 2 return: array Tables in an array (tablename is in both key and value) |
| admin_get_fields($tableName) X-Ref |
| Returns information about each field in the $table (quering the DBMS) In a DBAL this should look up the right handler for the table and return compatible information This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery. param: string Table name return: array Field information in an associative array with fieldname => field row |
| admin_get_keys($tableName) X-Ref |
| Returns information about each index key in the $table (quering the DBMS) In a DBAL this should look up the right handler for the table and return compatible information param: string Table name return: array Key information in a numeric array |
| admin_query($query) X-Ref |
| mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! Usage count/core: 10 param: string Query to execute return: pointer Result pointer |
| connectDB() X-Ref |
| Connects to database for TYPO3 sites: return: void |
| debug($func, $query='') X-Ref |
| Debug function: Outputs error if any param: string Function calling debug() param: string Last query if not last built query return: void |
| debug_check_recordset($res) X-Ref |
| Checks if recordset is valid and writes debugging inormation into devLog if not. param: resource $res Recordset return: boolean <code>false</code> if recordset is not valid |
| Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
|