Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql_real_escape_string() cannot connect to database..??

comp.lang.php
Guest
 
Posts: n/a
#1: Oct 11 '06
when trying to use the mysql_real_escape_string() function, the
following warning occurs:

Quote:
Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: Access denied for user
'web'@'localhost' (using password: NO) in
/home/me/web/include/secondary/app_action.inc.php on line 337

Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: A link to the server could not be
established in /home/me/web/include/secondary/app_action.inc.php on
line 337
First of all, the user is not 'web' trying to connect to the database,
secondly, what is mysql_real_escape_string() doing connecting to the
database, as 'web' or anyone else, and thirdly, why is this happening,
does anyone know?

Thanx
Phil


Kim André Akerĝ
Guest
 
Posts: n/a
#2: Oct 11 '06

re: mysql_real_escape_string() cannot connect to database..??


comp.lang.php wrote:
Quote:
when trying to use the mysql_real_escape_string() function, the
following warning occurs:
>
Quote:
Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: Access denied for user
'web'@'localhost' (using password: NO) in
/home/me/web/include/secondary/app_action.inc.php on line 337
>
Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: A link to the server could not be
established in /home/me/web/include/secondary/app_action.inc.php on
line 337
>
First of all, the user is not 'web' trying to connect to the database,
secondly, what is mysql_real_escape_string() doing connecting to the
database, as 'web' or anyone else, and thirdly, why is this happening,
does anyone know?
>
Thanx
Phil
Have you connected to your MySQL database yet?

From the manual:
-----------------------------
Escapes special characters in the unescaped_string, taking into account
the current character set of the connection so that it is safe to place
it in a mysql_query(). If binary data is to be inserted, this function
must be used.
-----------------------------
Note: A MySQL connection is required before using
mysql_real_escape_string() otherwise an error of level E_WARNING is
generated, and FALSE is returned. If link_identifier isn't defined, the
last MySQL connection is used.
-----------------------------

--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Johnny
Guest
 
Posts: n/a
#3: Oct 11 '06

re: mysql_real_escape_string() cannot connect to database..??



"comp.lang.php" <phillip.s.powell@gmail.comwrote in message
news:1160550516.487814.83740@k70g2000cwa.googlegro ups.com...
Quote:
when trying to use the mysql_real_escape_string() function, the
following warning occurs:
>
Quote:
Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: Access denied for user
'web'@'localhost' (using password: NO) in
/home/me/web/include/secondary/app_action.inc.php on line 337
>
Warning: mysql_real_escape_string()
[function.mysql-real-escape-string]: A link to the server could not be
established in /home/me/web/include/secondary/app_action.inc.php on
line 337
>
First of all, the user is not 'web' trying to connect to the database,
secondly, what is mysql_real_escape_string() doing connecting to the
database, as 'web' or anyone else, and thirdly, why is this happening,
does anyone know?
>
Thanx
Phil
>
if you are on an apache system then PHP is likely running as other (out of
user/group/other) and as a result may well be seen as 'web'

you don't give any context other than a line number for the error so it
makes it a litle harder to intuit what might be happening.

you could change the error reporting to notice to see extra warnings

A MySQL connection is required before using mysql_real_escape_string()
otherwise an error of level E_WARNING is generated...
so it may be that you don't have a valid mysql connection but without seeing
the context who knows?

here's what happens on my local server when I call that without a db link:

<?php echo mysql_real_escape_string("some text"); ?>

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]:
Access denied for user: 'ODBC@localhost' (Using password: NO) in i:\program
files\apache group\apache\htdocs\mres.php on line 1

but on my remote server the same thing gives:
Warning: mysql_real_escape_string(): Access denied for user:
'nobody@localhost' (Using password: NO)in
/home/user/public_html/sitename/mres.php on line 1

so as you can see the user that appears in the error depends on how your
sever is configured.


Closed Thread