602SQL Documentation Index  

Prepared SQL statement parameters

Parameters in a SQL statement are marked with a question mark ? (unlike the parameters in SQL statements executed by the wb_exec function). Parameters can be IN, OUT and INOUT. You can pass the parameter list to the wb_psql_execute function. The IN and INOUT parameter values are passed to the SQL Server, the SQL statement is executed and the OUT and INOUT parameter values are read and written to the specified PHP variables.

The SQL statement parameters can be passed either as parameters in the wb_psql_execute function, or you can pass the IN parameter values with the wb_psql_send_param function and read the OUT parameter values with the wb_psql_get_out_param function.

The value of the INOUT parameter must be passed to the SQL statement (as the IN parameters) and must be read (as the OUT parameters).

IN parameter value conversion

Conversion of the NULL PHP value

If the NULL value is passed for any IN parameter type, the SQL Server will receive the NULL value of the corresponding database type.

Other PHP value conversion

IN parameter type (db type)allowed PHP values
BOOLEAN boolean type values, or values that can be converted to this PHP type
TINYINT, SMALLINT, INTEGER, BIGINT int type values, or values that can be converted to this PHP type; if the value exceeds the specified database type range, an error will occur
NUMERIC, DECIMAL, REAL float type values, or values that can be converted to this PHP type; if the value exceeds the specified database type range, an error will occur
CHAR(N), CLOB string type values, or values that can be converted to this PHP type
NCHAR(N), NCLOB

string type values, or that can be converted to this PHP type; moreover:

  • If the client encoding is WB_ENC_ASCII, then the value must be an ASCII string
  • If the client encoding is WB_ENC_WIN1250, then the value must be a string in the Windows CP 1250 coding
  • If the client encoding is WB_ENC_WIN1252, then the value must be a string in the Windows CP 1252 coding
  • If the client encoding is WB_ENC_ISO_8859_2, then the value must be a string in the ISO-8859-2 coding
  • If the client encoding is WB_ENC_UTF8, then the value must be an UTF-8 string

The passed value will be sent to the SQL Server after it is converted to UCS-2 coding, however the original PHP value is unaffected.

DATE
  • Values of the int type, the number is taken as Unix time (the time instant that is a certain number of seconds from the Unix Epoch, 1.1.1970, 00:00 UTC) and the day (date) this instant belongs to is converted to the SQL DATE type
  • Values of the string type, the string must be a valid notation of the DATE type constant according to the 602SQL API Str2date function.
  • Other PHP type values will result in an error
TIME

Value of the string type, or value that can be converted to this type; the string must be a valid notation of a TIME type constant according to the 602SQL API Str2time function.

TIMESTAMP
  • Values of the int type, the number is taken as Unix time and the TIMESTAMP type value that belongs to the same time instant
  • Values of the string type, the string must be a valid notation of the TIMESTAMP according to the 602SQL API Str2timestamp function.
  • Other PHP type values will result in an error

OUT parameter value conversion

The NULL value

The NULL value will always return the PHP value NULL.

Other values

OUT parameter type (database type)PHP value
BOOLEAN PHP type boolean
Integer types up to 32-bits (e.g. TINYINT, SMALLINT and INTEGER) PHP type int
BIGINT If this value can be converted to a 32-bit int type, then it will be returned as a value of this type, otherwise it will return float (however in this case, number accuracy will be affected).
NUMERIC, DECIMAL, REAL PHP type float
CHAR(N), CLOB PHP type string
NCHAR(N), NCLOB PHP type string; the return string will be in UTF-8
DATE PHP type int; the return number is the time of the first second (e.g. 00:00) of that day, that is represented by the DATE type value
TIME PHP type string; the return string will contain the given time notation
TIMESTAMP PHP type int; the return string will be the Unix time of the time instant represented by the given TIMESTAMP type value
BINARY(N), BLOB PHP type string; each byte of the binary value will be represented with two characters, that represent the hexadecimal notation of the given byte
(e.g. the byte with ASCII code 32 (decadic) will be represented with the "20" substring; the byte with ASCII code 13 (decadic) will be represented with the substring "0d"