PEAR MDB2 provides several methods for querying databases. The most direct method is query(). It takes a SQL query string as an argument. There are two possible returns: A new MDB2_Result object for queries that return results (such as SELECT queries), or a MDB2_Error object on failure. It should not be used with statements that manipulate data (such as INSERT queries)
Пример 34-1. Doing a query
|
exec() should be used for manipulation queries. There are two possible returns: An integer denoting the number of affected rows for statements that manipulate data (such as INSERT queries), or a MDB2_Error object on failure. It should not be used with statements that return results (such as SELECT queries)
Пример 34-2. Using exec to manipulate data
|
MDB2 supports a number of data types across all drivers. These can be set for result sets in all relevant methods. You can find an overview of the supported data types and their format here.
In order to read/write to only a limited number of rows from a result set and/or to start reading from a specific offset the setLimit() can be called prior to issueing the query. The limit and offset will only affected the next method call that will issue a query or prepare a statement and will automatically be reset after issueing the query. This also applies to any internal queries issues inside MDB2. Note that limit may not work with DML statements on RDBMS that emulate limit support and no error will be raised.
Пример 34-3. Using setLimit with query and exec
|
Пред. | Начало | След. |
Connecting | Уровень выше | Quoting and escaping |
HIVE: All information for read only. Please respect copyright! |