|
wb_client_encoding | Auxiliary Functions | wb_script_encoding |
This function sets:
One of the following codings can be used:
This setting is applied upon execution of the SQL statement that contains references to PHP variables (host variables prefixed by :<> or dynamic parameters marked with a question mark in the prepared statement) with text (PHP variables of the string type) using the wb_exec or wb_psql_execute function. If the WB_ENC_UTF8 coding is set when executing this statement, the values of the PHP string type variables that are used in the SQL statement will be converted from UTF-8 coding to UCS-2 coding and will be passed to the SQL Server in this coding. 602SQL Server does not support UTF-8 coding, it only supports UCS-2 coding.
Furthermore, this setting is used when calling the wb_lob_write function. If WB_ENC_UTF8 is set, data is converted from UTF-8 to UCS-2 before being written to a NCLOB variable (variable-length Unicode text).
If WB_ENC_ASCII, WB_ENC_WIN1250, WB_ENC_WIN1252 or WB_ENC_ISO_8859_2 coding is set, the text will be converted to UCS-2 coding when string is written to a column.
This setting is not applied when reading values from the database using the wb_result or wb_fetch_into function, or when passing the PHP variables that are not a string type. It is also not applied when calling the wb_lob_read function.
TRUE if successful, otherwise FALSE (when the coding to be set is not supported).
Write the string in UTF-8 coding to the column type NCHAR:
/* let the $str variable contain a string in the UTF-8 coding, that we want to write into the UNI_STR column in the UNI_TABLE table*/ // first we set the coding of the PHP variables with texts, that will be passed into the SQL statement wb_set_client_encoding($connection , WB_ENC_UTF8); // and the $str variable value will be passed to the SQL server in the UCS-2 coding wb_exec($connection,"INSERT INTO UNI_TABLE(UNI_STR) VALUES(:<str);"); // now if we want to pass PHP variables with text in ASCII coding to the SQL statement, // we must change the coding wb_set_client_encoding($connection,WB_ENC_ASCII); // and execute the SQL statements
Write a string in the Windows CP 1250 coding to the column type NCHAR:
// we assume that the source text is in the Windows CP 1250 coding $str="příliš žluťoučký kůň úpěl ďábelské ódy"; // set the coding to Windows CP 1250 wb_set_client_encoding($connection, WB_ENC_WIN1250); // prepare the SQL statement $stmt=wb_psql_prepare($connection, "INSERT INTO UNI_TABLE(UNI_STR) VALUES(?);"); // execute the SQL statement wb_psql_execute($stmt, $str); // reset to the original coding wb_set_client_encoding($connection, WB_ENC_ASCII);
wb_client_encoding | Auxiliary Functions | wb_script_encoding |