addslashes/mysql_real_escape_string

This is a discussion on addslashes/mysql_real_escape_string within the PHP Language forums, part of the PHP Programming Forums category; > mysql_real_escape_string() is not meant to be taking objects. It > requires a string. If you want to do this, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #21 (permalink)  
Old 03-30-2008
Gabest
 
Posts: n/a
Default Re: addslashes/mysql_real_escape_string

> mysql_real_escape_string() is not meant to be taking objects. It
> requires a string. If you want to do this, you need a __tostring()
> method in your class to convert to a string.
>
> Or, if you want to bring it back out into a string later, you should
> first serialize() the object, then after retrieval, unserialize() it.


This is not my class, SimpleXMLElement is an inbuilt class of php. You
can read an xml file into a variable and say "echo $xml->person-
>name", it will interpret it as a string and does not leak any memory.

If one function lets you rely on autocasting the other does not, then
php becomes a mine field for the programmer, or __tostring() can be
declared a broken idea.
Reply With Quote
  #22 (permalink)  
Old 03-31-2008
Jerry Stuckle
 
Posts: n/a
Default Re: addslashes/mysql_real_escape_string

Gabest wrote:
>> mysql_real_escape_string() is not meant to be taking objects. It
>> requires a string. If you want to do this, you need a __tostring()
>> method in your class to convert to a string.
>>
>> Or, if you want to bring it back out into a string later, you should
>> first serialize() the object, then after retrieval, unserialize() it.

>
> This is not my class, SimpleXMLElement is an inbuilt class of php. You
> can read an xml file into a variable and say "echo $xml->person-
>> name", it will interpret it as a string and does not leak any memory.

> If one function lets you rely on autocasting the other does not, then
> php becomes a mine field for the programmer, or __tostring() can be
> declared a broken idea.
>


Makes no difference. mysql_real_escape_string() should be used for
STRINGS, not objects. Results in the latter case are unpredictable.

If you want to store an object of the simplexml class in your database,
you should derive your own class from it and implement the __tostring()
method. Or serialize the object and store it.

__tostring() is not meant to be a replacement for serialize().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0