Oracle 5.0 Reference Manual page 2199

Table of Contents

Advertisement

Note that
mysql
the character set in use by the server.
Description
This function is used to create a legal SQL string that you can use in an SQL statement. See
Section 9.1.1, "String
The string in
set of the connection. The result is placed in
encoded are "\", "'", """,
only that backslash and the quote character used to quote the string in the query be escaped.
mysql_real_escape_string()
files. For comparison, see the quoting rules for literal strings and the
Section 9.1.1, "String
The string pointed to by
least
length*2+1
two bytes, and you need room for the terminating null byte.) When
returns, the contents of
string, not including the terminating null character.
If you need to change the character set of the connection, use the
function rather than executing a
mysql_set_character_set()
mysql_real_escape_string(), which
Example
char query[1000],*end;
end = strmov(query,"INSERT INTO test_table values(");
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"What is this",12);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"binary data: \0\r\n",16);
*end++ = '\'';
*end++ = ')';
if (mysql_real_query(&mysql,query,(unsigned int) (end - query)))
{
fprintf(stderr, "Failed to insert row, Error: %s\n",
mysql_error(&mysql));
}
The
strmov()
like
strcpy()
Return Values
The length of the value placed into to, not including the terminating null character.
Errors
None.
20.6.6.54.
mysql_real_query()
int mysql_real_query(MYSQL *mysql, const char *stmt_str, unsigned long
length)
C API Function Descriptions
must be a valid, open connection. This is needed because the escaping depends on
Literals".
is encoded to an escaped SQL string, taking into account the current character
from
(ASCII 0), "\n", "\r", and Control+Z. Strictly speaking, MySQL requires
NUL
quotes the other characters to make them easier to read in log
Literals", and
Section 12.5, "String
must be
from
bytes long. (In the worst case, each character may need to be encoded as using
is a null-terminated string. The return value is the length of the encoded
to
SET NAMES
works like
function used in the example is included in the
but returns a pointer to the terminating null of the first parameter.
and a terminating null byte is appended. Characters
to
Functions".
bytes long. You must allocate the
length
(or
SET CHARACTER
but also affects the character set used by
SET NAMES
does not.
SET NAMES
2179
[892]
SQL function in
QUOTE()
buffer to be at
to
mysql_real_escape_string()
mysql_set_character_set()
SET) statement.
library and works
libmysqlclient

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents