Copied from http://wiki.simplemachines.org/smf/index.php?title=$smcFunc/sandbox&oldid=13657 |
m Added needs work |
||
Line 1: | Line 1: | ||
<!-- Please do not remove -->__NOEDITSECTION__<!-- | <!-- Please do not remove -->__NOEDITSECTION__<!-- | ||
-->{{TOCright}} | -->{{TOCright}} | ||
{{needs_work}} | |||
These functions are used throught SMF code in order to deal with different versions of php, different character sets, and different databases. | These functions are used throught SMF code in order to deal with different versions of php, different character sets, and different databases. | ||
==String Utility Functions== | ==String Utility Functions== |
Revision as of 15:56, 23 May 2013
![]() |
This article needs some work for the following reason: (no reason given) This template may be removed when cleanup is complete. |
These functions are used throught SMF code in order to deal with different versions of php, different character sets, and different databases.
String Utility Functions
These functions are defined in function reloadSettings, in Load.php. Some of these functions have the same name as standard PHP functions, but were designed to deal uniformly with UTF-8 character sets, HTML entities, and differences in behavior in different versions of PHP. It is recommended that they be used instead of the functions they replace.
Database Functions
In SMF 2.0, multiple database support was introduced. This was implemented by developers as a new layer of database functions along with a new security model, which provides a fast and secure method to work across database systems. Below is a list of the database functions that currently exist in 2.0. Each of these links will direct you towards a section about that function that will help you understand what each one does, how its input is expected and if possible, the exact duplicate function for mysql. An example is provided as well for most of these, these examples come straight from the SMF Source code.
Please note our Function Database now has detailed information on the latest SMF 2.0 functions. For each of the smcFunc entries below, you will find a corresponding function name with an 'smf_' prefix. So, for $smcFunc['db_insert'], see the function 'smf_db_insert'.
Function | Usage | Description |
---|---|---|
db_query | $smcFunc['db_query'] (identifier, query, values, connection) |
Executes a database query. Works similar to how db_query worked in SMF 1.x. |
db_fetch_assoc | $smcFunc['db_fetch_assoc'] ($result) |
Will return exact same results as mysql_fetch_assoc |
db_fetch_row | $smcFunc['db_fetch_row'] (result) |
return the exact same results as mysql_fetch_row. Frequently used when is known the query returns only one row of data. |
db_insert | $smcFunc['db_insert'] (method, table, columns, data, keys, disable_trans, connection) |
Insert data into the database. |
db_free_result | $smcFunc['db_free_result'] (result) |
Frees the memory in use by the result from a query. Works exactly as mysql_free_result. This is usually called after the data has been fetched from the database. |
db_affected_rows | $smcFunc['db_affected_rows'] (connection) |
Works exactly as mysql_affected_rows. |
db_case_sensitive | $smcFunc['db_case_sensitive'] |
Tells SMF whether the database is case sensitive (PostgreSQL and SQlite) or not (MySQL). Shall not be called as a function, but used a boolean. |
db_data_seek | $smcFunc['db_data_seek'] (result, row_number) |
Works exactly like mysql_data_seek, it moves the internal row pointer for result to the row specified in row_number. Emulated while using PostgreSQL with smf_db_data_seek. |
db_error | $smcFunc['db_error'] (connection) |
Will return the exact same results as mysql_error. |
db_insert_id | $smcFunc['db_insert_id'] (table, field, connect) |
Will return exact same results as mysql_insert_id. |
db_num_fields | $smcFunc['db_num_fields'] (result) |
Works exactly like mysql_num_fields. It gets the number of fields in a result. |
db_num_rows | $smcFunc['db_num_rows'] (result) |
Used to obtain the number of rows of a query. It works exactly like mysql_num_rows. |
db_select_db | $smcFunc['db_select_db'] (database_name, connection) |
In MySQL the function selects a database like the function mysql_select_db. In PostgreSQL returns always true since the database is selected upon creating the connection. In SQlite will do nothing as there is only one database per file. |
db_server_info | $smcFunc['db_server_info'] (connection) |
Attempts to get database server information |
db_sybase | $smcFunc['db_sybase'] |
Tells SMF whether the database uses sybase (PostgreSQL and SQlite) or not (MySQL). Shall not be called as a function, but used a boolean. |
db_title | $smcFunc['db_title'] |
Name of the database being used. Such as MySQL, PostgreSQL and SQlite. Shall not be called as a function, but used a string. |
Database Package Functions
Function | Usage | Description |
---|---|---|
db_add_column | $smcFunc['db_add_column'](table_name, column_info, parameters, if_exists, error) |
This function is used to add a new column to an existing table. |
db_add_index | $smcFunc['db_add_index'](table_name, index_info, parameters, if_exists, error) |
This function allows for adding an index to a table. |
db_calculate_type | $smcFunc['db_calculate_type'](type_name, type_size, reverse) |
This function will calculate the type and size for a column. |
db_change_column | $smcFunc['db_change_column'] (table_name, old_column, column_info, parameters, error) |
This function allows for changing an existing column structure. |
db_create_table | $smcFunc['db_create_table'] (table_name, columns, indexes, parameters, if_exists, error) |
This function allows for creating a table. You can not create a SMF default table. |
db_drop_table | $smcFunc['db_drop_table'] (table_name, parameters, error) |
This function allows for removal a table. You can not delete a SMF default table. |
db_list_columns | $smcFunc['db_list_columns'] (table_name, detail, parameters) |
This function returns the current columns in a table in a multi-dimensional array. |
db_list_indexes | $smcFunc['db_list_indexes'](table_name, detail, parameters) |
This function returns the current indexes in a table in a multi-dimensional array. |
db_remove_column | $smcFunc['db_remove_column'](table_name, column_name, parameters, error) |
This function removes a column. |
db_remove_index | $smcFunc['db_remove_index'](table_name, index_name, parameters, error) |
This function removes a index. |
db_table_structure | $smcFunc['db_table_structure'] (table_name) |
This function returns the structure of a table. |
Other functions
These functions are only used internally by other $smcFunc functions, and should not be called directly.
Function | Usage |
---|---|
db_escape_string | Escapes strings for insertion into the database. The function does not require a database connection. For MySQL addslashes is used, while for PostgreSQL pg_escape_string and for SQLite sqlite_escape_string as used. |
db_quote | Formats the query as db_query does, but it does not execute the query. Used to prepare parts of query to be used later on. |
db_transaction | Same as calling queries for "BEGIN", "ROLLBACK", and "COMMIT". |
db_unescape_string | Unescapes a string. The opposite of db_escape_string. |
entity_fix | Only used by other string utility functions, such as htmlspecialchars, htmltrim, strpos, substr, and truncate to deal with numerical html entities found in the string. These functions are important to the way SMF deals with user-input characters that are outside the forum's declared character set. |