FastSitePHP\Data\Db2Database

IBM - DB2 and AS/400 Databases

This class provides a thin wrapper for PHP DB2 functions. It reduces the amount of code needed to query IBM databases and provides a compatible class with FastSitePHP's Database class.

The IBM DB2 Drivers needed to run this class will not be available on most systems however on an IBM Server such as AIX (AS/400) that has PHP installed the driver will likely be available by default.

On IBM Servers PHP is typically installed through Zend Server. PHP supports IBM Severs so the versions of PHP 7.# can be installed on old IBM Servers.

If using this class directly on the server you can use the server's credentials and pass [null] for [DSN, User, and Password]. In fact this is recommended as you can get better performance. If empty strings '' are used as shown in the PHP docs online it can cause extra print spool jobs to run so use [null] instead.

Source Code

GitHub

Properties

Name Data Type Default Description
db null
resource
null Connection for the Database

Methods

__construct($dsn, $user = null, $password = null, $persistent = false, $options = null)

Class Constructor. Creates Db Connection.

__destruct()

Class Deconstructor. Calls [close()] automatically unless using a Persistent Connection.

close()

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.

Returns: array

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.

Returns: 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.

Returns: mixed

queryList($sql, array $params = null)

Query for an array of values from the first column of all records found.

Returns: array

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.

Returns: 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.

Returns: int

trimStrings($new_value = null)

Getter / Setter Property

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.

Returns: bool | $this