cubrid_real_escape_string
(PECL CUBRID >= 8.3.0)
cubrid_real_escape_string — Escape special characters in a string for use in an SQL statement
Description
$unescaped_string
[, resource $conn_identifier
] ) : string
This function returns the escaped string version of the given string. It
will escape the following characters: '
.
In general, single quotations are used to enclose character string. Double
quotations may be used as well depending on the value of ansi_quotes,
which is a parameter related to SQL statement. If the ansi_quotes value is
set to no, character string enclosed by double quotations is handled as
character string, not as an identifier. The default value is yes.
If you want to include a single quote as part of a character string, enter
two single quotes in a row.
Parameters
-
unescaped_string
-
The string that is to be escaped.
-
conn_identifier
-
The CUBRID connection. If the connection identifier is not specified, the last connection opened by cubrid_connect() is assumed.
Examples
Example #1 cubrid_real_escape_string() example
<?php
$conn = cubrid_connect("localhost", 33000, "demodb");
$unescaped_str = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$escaped_str = cubrid_real_escape_string($unescaped_str);
$len = strlen($unescaped_str);
@cubrid_execute($conn, "DROP TABLE cubrid_test");
cubrid_execute($conn, "CREATE TABLE cubrid_test (t char($len))");
cubrid_execute($conn, "INSERT INTO cubrid_test (t) VALUES('$escaped_str')");
$req = cubrid_execute($conn, "SELECT * FROM cubrid_test");
$row = cubrid_fetch_assoc($req);
var_dump($row);
cubrid_close_request($req);
cubrid_disconnect($conn);
?>
The above example will output:
array(1) { ["t"]=> string(95) " !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" }
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.cubrid-real-escape-string.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.