Re: Using mysql_real_escape_string without connecting to mysql
| From: | Dotan Cohen | Date: | Wed, 23 Jan 2008 18:47:43 +0000 |
| Subject: | Re: Using mysql_real_escape_string without connecting to mysql | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267918@lists.php.net to get a copy of this message | ||
On 23/01/2008, Eric Butera <eric.butera@gmail.com> wrote:
> On Jan 22, 2008 8:01 PM, Dotan Cohen <dotancohen@gmail.com> wrote:
> > I have a file of my own functions that I include in many places. One
> > of them uses mysql_real_escape_string, however, it may be called in a
> > context that will or will not connect to a mysql server, and worse,
> > may already be connected. So I must avoid connecting. However, when I
> > run the script without connecting I get this error:
> >
> > Warning: mysql_real_escape_string()
> > [function.mysql-real-escape-string]: Access denied for user:
> > 'nobody@localhost' (Using password: NO)
> >
> > I was thinking about checking if there is a connection, and if not
> > then connecting. This seems redundant to me, however. What is the
> > list's opinion of this situation? Thanks in advance.
> >
> > Dotan Cohen
> >
> > http://what-is-what.com
> > http://gibberish.co.il
> > א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
> >
> > A: Because it messes up the order in which people normally read text.
> > Q: Why is top-posting such a bad thing?
> >
>
> By not connecting to the server you don't have the correct context for
> using mysql real escape string, therefore it is pointless.
>
Yes, I realize this. Note that I _always_ connect via UTF-8, so I'd
like to tell mysql_real_escape_string to do it's magic as if I were
connected via UTF-8. I realize that this is impossible.
However, I do not think that the script should throw an error until I
actually call mysql_clean. Merely having it in an include should not
throw an error if the function is not being used.
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?