| Skrol29, 2010-08-19 | TbsSQL 3.0 |
| - | %1% | The joker will be replaced with 1st argument protected against SQL injection. |
| - | @1@ | The joker will be replaced with 1st argument protected against SQL injection and delimited using the relevant string delimiter of the database. |
| - | #1# | The joker will be replaced with 1st argument converted into a date value (without time part) using the relevant date format of the database. |
| - | ~1~ | The joker will be replaced with 1st argument converted into a date-time value using the relevant date-time format of the database. |
| $Db->Execute($sql [,$val1, $val2, ...]) | Execute the Sql statement. Argument $sql can contain placeholders for $val1, val2, ... |
| $Db->GetVal($sql [,$val1, $val2, ...]) | Returns the value of the first column in the first record of the query. If no record is returned by the query, then the function returns false. Argument $sql can contain placeholders for $val1, val2, ... |
| $Db->GetRow([$rowtype,] $sql [,$val1, $val2, ...]) | Returns the first record returned by the query. Return false in case of no record. You can precise the row type for this query using argument $rowtype. See property DefaultRowType for accepted values. If argument $rowtype is omitted, then the returned row type depends of property DefaultRowType. Argument $sql can contain placeholders for $val1, val2, ... |
| $Db->GetRows([$rowtype,] $sql [,$val1, $val2, ...]) | Returns all records returned by the query. Return an empty array in case of no record. You can precise the row type for this query using argument $rowtype. See property DefaultRowType for accepted values. If argument $rowtype is omitted, then the returned row type depends of property DefaultRowType. Argument $sql can contain placeholders for $val1, val2, ... |
| $Db->GetList($sql [,$val1, $val2, ...]) | Returns a PHP array with first column as keys and second column as values. If only one columns is given by the query then they the values of the array. Example: $Db->GetList('SELECT id,name FROM t_people');
Argument $sql can contain placeholders for $val1, val2, ...will return something like: array(1=>'Peter', 2=>'Dave', 3=>'Jane' ,...) |
| $Db->GetSql($sql [,$val1, $val2, ...]) | Returns the SQL statement with merged arguments. Argument $sql can contain placeholders for $val1, val2, ... |
| $Db->LastRowId() | Returns the value of the identifier generated by the last INSERT query of your connection. Note: This method is not available for ODBC Generic. |
| $Db->AffectedRows() | Returns the number of rows affected by the last UPDATE or DELETE query of your connection. Note: This method is not available for ODBC Generic. |
What is the TbsSQL cache feature? SQL queries results can be saved in cache files in order to save time execution when they are recalled. Cache files are available for a limited duration (timeout) in order to ensure the actualization of the data.
The TbsSQL cache feature is disabled by default. You can enable it simply by setting a positive value to property $Db->CacheTimeout.
Interesting technical notes:
-
TbsSQL cache files cannot be read by users because they are PHP files.
-
The TbsSQL cache feature will never provide data from another SQL query. Other tools, like ezSQL for example, can theoretically be wrong when identifying a cache file because they are identified only by a hash value (md5). Hash values are not unique ids, even if the probability of doubles is very poor.
-
When the cache is enabled, TbsSQL will (by default) automatically get rid of cache files that come from old unused queries.
| $Db->CacheTimeout | Defines the cache timeout in minutes for all SQL queries called by methods GetVal(), GetRow(), GetRows() and GetList(). The default value is false, which means the cache feature is disabled. Method Execute() is not concerned by the cache feature. You can use constants TBSSQL_1HOUR, TBSSQL_1DAY or TBSSQL_1WEEK in order to easier define the timeout. Use property TempCacheTimeout to force the cache for only one query, whether default cache is enabled or not. Example: $Db->CacheTimeout = 2 * TBSSQL_1DAY; this does enable the cache for all queries with a cache duration of one day. |
| $Db->TempCacheTimeout | Define the cache timeout in minutes but only for the next query. You can use this property to active the cache for only one query, or to change the cache timeout for a only one query. Default value is false, which means there is no special timeout for the next query. If the cache is enabled (i.e. CacheTimeout > 0), you can disable the cache only for the next query by setting TempCacheTimeout to TBSSQL_NOCACHE. Example: $Db->TempCacheTimeout = TBSSQL_1DAY; $x = $Db->GetRows('SELECT id, name FROM table1 ORDER BY id'); |
| $Db->CacheAutoClear | When the cache is enabled, TbsSQL can try to delete old cached queries in the cache directory. The default value is TBSSQL_1WEEK. |
| $Db->CacheDir | This property defines the directory where cached queries are stored. The default value is '.'. |
| $Db->CacheSuffix | Default value is '' (empty string). This property enables you to add a suffix in the cache file names. You do not need it most of the time. It is designed to separate the cached results for the same SQL queries string, for example when a project may use the same queries in two different Databases. |
| $Db->CacheTimestamp($sql) | Returns the timestamp of the cache file corresponding to $sql. Returns false if the SQL has no cache file. |
| $Db->CacheFileName($sql) | Returns the file path of the cache file corresponding to $sql. Returns false if the SQL has no cache file. |
| $Db->CacheDelete($sql) | Try to delete the cache file corresponding to $sql. Returns true if succeed, otherwise returns false. |
| $Db->TbsKey | (read) Return the TinyButStrong key string for the current connection (see chapter Hook above). This property has always a default value which is unique for each new instance. Most of the time there is no need know the value of this property, since you can use the property directly with TBS. Example: $TBS->MergeBlock('b',$Db->TbsKey,'SELECT * FROM table1'); Versioning: this property is available since TbsSQL version 2.5 |
| $Db->SetTbsKey($key) | Change the value of property $Db->TbsKey. Most of the time, there is no need to use this method because property TbsKey has always a default value which is unique. Use this method only if your application do need a customized key value for the TinyButStrong merging. Example: $Db->SetTbsKey('myconnection');
$TBS->MergeBlock('b', 'myconnection', 'SELECT * FROM table1'); Versioning: this method is available since TbsSQL version 2.5 |
Those methods are deprecated in TbsSQL version 2.x, and unsupported since version 3.x
| $Db->Row1($sql,...*...) | Same as $Db->GetRow() |
| $Db->Rows($sql,...*...) | Same as $Db->GetRows() |
| $Db->Value($default,$sql,...*...) | Same as $Db->GetVal() but with a default value. |
Version 3.0, 2010-08-19
- New cache feature
- Can return records as objects (as stdClass instances, or as your own class instances or as clones of any instances)
- Can return trace in a console, and can trace data in a grid
- New property Version (is it useful?)
- More compatibility with PHP 4
- Can handle dates over the 32bit limits (1970-2038) if PHP => 5.2
- Trace mode now works when TbsSQL is used within TinyButStrong
Version 2.6, 2009-11-26
- Argument $Mode has been added to the class instantiation and to method Connect().
This allows to display error message and trace when the connection is made.
- Display the connection string in trace mode (Mode=TBSSQL_TRACE)
- New database support : ODBC (generic), for both Windows and Unix)
- Support UnixODBC for ODBC Generic and ODBC for SQL Server.
- Use canonical formats for date and time with ODBC Generic and ODBC for SQL Server.
- Support ODBC connection string with ODBC and ODBC Generic for SQL Server.
- Do not use @ with odbc_connect() because some error of connection can make a PHP critical error.
In this case @ avoid any error and warning messages which is uncomfortable.
Version 2.5, 2009-09-16
- New set of jokers that supports NULL values for SQL.
- constants that can be used for property $Db->Mode :
TBSSQL_SILENT
TBSSQL_NORMAL
TBSSQL_DEBUG
TBSSQL_TRACE
- Bug for TbsSQL with MySQL : each TbsSQL instance was always linked to the
last MySQL connection. That was because property $Db->Id was always set to True
instead of the MySQL connection resource.
- New property $Db->TbsKey : enables you to use several instances of TbsSQL with TinyButStrong.
- New method $Db->SetTbsKey() : enables you to customize instances of TbsSQL with TinyButStrong.