Reply to Re: mysql_real_escape_string()

Your name:

Reply:


Posted by zach on 08/05/07 07:29

Matt Madrid wrote:
> zach wrote:
>> Matt Madrid wrote:
>>> zach wrote:
>>>> Ok, something that confuses me is why does mysql_real_escape_string
>>>> need a link or connection to the database if its simply escaping a
>>>> string. I thought the whole point was to do the work before it ever
>>>> goes to a database, so I wouldn't expect it to need a connection.
>>>
>>> The documentation at:
>>> http://www.php.net/manual/en/function.mysql-real-escape-string.php
>>> says: "mysql_real_escape_string() calls MySQL's library function
>>> mysql_real_escape_string"
>>>
>>> ... and the documentation at:
>>> http://dev.mysql.com/doc/refman/5.0/en/mysql-real-escape-string.html
>>> says: "must be a valid, open connection. This is needed because the
>>> escaping depends on the character set in use by the server."
>>
>> That's what I was looking for. Thanks.
>>
>>>
>>> The php documentation also says: "If no such link is found, it will
>>> try to create one as if mysql_connect() was called with no arguments."
>>
>>
>>> RTFM... ;-)
>>
>> I read the manual
>
> I'm sure you did.. I was trying to get you to read it again.
>
>> which is how I knew it needed an open connection.
>
> ahh.. this is why I threw in that last part about it trying to open a
> connection itself if none is found. If you found this out by reading the
> docs, and not because you got an error, it means that you might have a
> mysql server running on the same system that was automatically connected
> to, and so mysql_real_escape_string() works even though you didn't open
> a connection or give it one as an argument.
>
> But what if you are actually connecting to a different server with a
> different charset *after* using mysql_real_escape_string(). Then you
> might have some problems.
>
>> The manual only said it needed an open connection, but didn't
>> explain,(or not very clearly) why it needed it. Not everyone is so
>> inexperienced as to completely ignore the manual.
>
> Some people are. Wasn't trying to be rude, just point you in the right
> direction.
>
> Matt M.
>
>

I found it out both ways, I first got an error, read the manual, and
fixed it. That when I got confused because I couldn't figure out why it
needed the connection. Thanks for the help.

zach

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация