This class provides a thin wrapper for PHP ODBC functions. It reduces the amount of code needed to query a database and provides a compatible class with FastSitePHP's Database class.
ODBC is most common on Windows and especially on older servers or databases. In most cases PDO (FastSitePHP class [Database]) is preferred and will provide more recent drivers however if ODBC with PDO is not available the ODBC on a server then ODBC functions might be. Additionally certain databases such as IBM may only work through ODBC on some servers.
IMPORTANT - If using this class you may need to call the fuction [allowLargeTextValues()] if working with records that have large text or binary data.
|null||Connection for the Database|
allowLargeTextValues($size = 100000)
Use when needed to make sure that ODBC will return large text fields. By default only the first 4096 characters are returned.
This sets the PHP INI Setting 'odbc.defaultlrl' to the specified size.
__construct($dsn, $user = null, $password = null, $persistent = false, $options = null)
Class Constructor. Creates Db Connection.
Class Deconstructor. Calls [close()] automatically unless using a Persistent Connection.
Close the connection
query($sql, array $params = null)
Run a Query and return results as any array of records. Records are each associative arrays. If no records are found an empty array is returned.
queryOne($sql, array $params = null)
Query for a single record and return it as a associative array or return null if the record does not exist.
返回类型: array | null
queryValue($sql, array $params = null)
Query for a single value from the first column of the first record found. If no records were found null is returned.
queryList($sql, array $params = null)
Query for an array of values from the first column of all records found.
execute($sql, array $params = null)
Run a SQL Action Statement (INSERT, UPDATE, DELETE, etc) and return the number or rows affected. If multiple statments are passed then the returned row count will likely be for only the last query.
返回类型: int - Row count of the last query
executeMany($sql, array $records)
Prepare a SQL Statement and run many record parameters against it. This can be used for transactions such as bulk record inserts. Returns the total number of rows affected for all queries.
trimStrings($new_value = null)
Get or set whether spaces on strings should be trimmed when calling [query(), queryOne(), queryValue(), queryList(), querySets()].
When called strings are trimmed after the records are queried and before the function returns the result.
Often legacy databases will use [CHAR] text fields over [VARCHAR] or similar types. For example when using a [CHAR] field:
Field: [name] CHAR(20)
Data saved as "John "
When querying by default the spaces will be returned however if this function is set to [true] then "John" would be returned.
Defaults to [false]. Calling this function takes extra memory vs not using it so if you have a high traffic site and want to trim strings you may want to do so in the SQL Statement and keep this [false].
For a small amount of records (several hundred or less) this has little or not noticeable impact however if using a large set of records (1,000+) this setting may cause a about a 10% increase in memory or more.
返回类型: bool | $this