602SQL Documentation Index  



boolean wb_set_script_encoding( int encoding_id [, resource connection] )


Encoding to be set. This must be one of the constants WB_ENC_xxx. Mandatory parameter.
Opened connection to the 602SQL server (this value is returned by the wb_connect or wb_pconnect function). Optional parameter. If this parameter is set the wb_set_client_encoding function with parameters connection and encoding_id will be executed as well.


A SQL server accepts the text of SQL statements in the encoding specified upon its creation. This encoding may differ from the encoding of the PHP script, therefore the national characters in SQL statements may get corrupted.

Incorrect interpretation may also occur for national characters getting out of the database, because the PHP script is written in another encoding.

The wb_set_script_encoding function therefore:

  1. converts the strings from the script that are sent to the SQL server from the script encoding into the database system encoding
  2. converts the string read from the database and provided to the PHP script from the system encoding into the script encoding

If the PHP script encoding is different than WB_ENC_UNKNOWN, then the following conversions are done:

From the PHP script encoding into the database system encoding:

From the database system encoding into the PHP script encoding

When reading values of the CHAR(n) or CLOB types using the wb_result and wb_fetch_into functions, that value will be converted into the PHP script encoding. BEWARE: Unicode strings/CLOBs will ALWAYS be read in the UTF-8 encoding!!!

When reading the values of OUT and INOUT parameters of the CHAR(n) nd CLOB types in SQL statement executed by the wb_exec and wb_psql_execute functions, the values will be converted into the PHP script encoding. UNICODE values are always converted into the UTF-8 encoding. The output values of string OUT and INOUT parameters read by the wb_psql_get_out_param function are converted in the same way.

Output values if client variables of the CHAR(n) and CLOB types that are passed to the wb_import_from_XML and wb_export_to_XML and wb_import_from_XML_buffer and wb_export_to_XML_buffer functions will be converted into the PHP script encoding. The output UNICODE parameter values are always converted into UTF-8.

Supported charsets:


TRUE if successful, FALSE otherwise.


Display contents of a SELECT, that has differently encoded columns, in UTF-8.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<h1>Text with national characters may be here if the file is stored in the UTF-8 coding)</h1>
 $dsn = "sql95test";
 $appl = "_all_tests";
 $dbuser = "";
 $conn=wb_connect($dsn, $appl, $dbuser);

$cursor=wb_exec($conn, "select * from Addresses");

while (wb_fetch_into($cursor, $buff)) {
	for ($i=1; $i<=wb_num_fields($cursor);$i++){
		echo wb_field_name($cursor, $i).": $buff[$i]<br>";
	echo "<br>";