602SQL Documentation Index  

Passing values from 602SQL to PHP

PHP has four basic types: boolean, long, string and real. It is described here how 602SQL values are handled when passed into PHP types (when reading the column values of the current record in the cursor with the wb_result function, or when passing the OUT parameters of the SQL statements when using the host variables (prefixed with :<>). Passing variables using the parameters of the prepared functions has somewhat different rules.

NULL value

The NULL value of any type is always read from the database into PHP as the PHP value NULL. This behaviour is expected for common types (number types, date and time types, etc.). However, you must keep in mind when working with string types (both fixed-length or variable-length) the database value "empty string" is passed into PHP as the PHP NULL value.


These types can be directly converted to the appropriate PHP type. All integer types are converted into PHP LONG type. The CHAR type is converted into a single character string. All string types with fixed length are converted into a string.


If these types have a decimal type, they will be converted into the REAL type, otherwise into the LONG type.

Unicode string types (NCHAR)

Unicode strings are stored in 602SQL in UCS-2 coding, but PHP works more efficiently with strings in UTF-8 coding. Therefore, the PHP module automatically converts Unicode strings into UTF-8.


The time types are converted in two different ways. The TIME type is converted into a readable string, the DATE and TIMESTAMP types are converted into the long type, and the number of seconds since the Unix Epoch is returned (January 1st 1970). You can work with this format using common PHP tools (e.g. format it with the date() function).


The BIGINT type is converted either to a LONG or REAL according to the size. This may lead to information loss, therefore it is better to avoid this conversion (e.g. by using a conversion in the SQL query).

Binary strings with a fixed length

Binary type columns, BINARY(n), where n<=4090. These values are read as a string PHP type value. If the wb_binmode parameter has the WB_CONVERT value when reading the value, the binary value will be converted into hexadecimal notation (e.g. the "ab" value will be converted into "6162", since the ASCII value of "a" is 61 and "b" is 62 in hexadecimal). If the wb_binmode parameter has any other value, the fixed length binary string will be read as a PHP string without conversion.

Types with variable length

This situation is more complicated for variable-length types (CLOB, NCLOB and BLOB). Detailed information about reading these values can be found on the Manipulating variable-length type variables in PHP page.