Jump to content

Odd PHP Error with mysql_real_escape_string()


kratsg

Recommended Posts

I just started getting this error, had no problems with this thing before...

 

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/SOME SITE STRUCTURE TO FILE/index.php on line 17

 

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/SOME SITE STRUCTURE TO FILE/index.php on line 17

 

And of course, line 17 is just this generalized statement:

 

$something = mysql_real_escape_string($something_else);

 

Any ideas?

 

 

Current PHP Version: PHP Version 4.3.4

 

MySQL Info:

 

Active Persistent Links 0

Active Links 0

Client API version 3.23.49

MYSQL_MODULE_TYPE builtin

MYSQL_SOCKET /tmp/mysql.sock

MYSQL_INCLUDE no value

MYSQL_LIBS no value

Link to comment
Share on other sites

That's the problem. It didn't show this error before (a week ago) and this script does not connect to the database in anyway at all.

 

I wanted to use the mysql_real_escape_string() as I use it to validate user input for logging in (via htaccess/htpasswd files and HTTP Portal Access).

 

I have another script which connects to my database successfully so I know that connections to the database are successful.

Link to comment
Share on other sites

The mysql_real_escape_string() function requires a current connection to a mysql server to work (read the manual.) If there is not a current connection to a mysql server, the mysql_real_escape_string() function will attempt to create one using all default connection settings, which will usually fail, which is what the error message indicates.

 

If the code this is in "does not connect to the database in anyway at all", then the code was never doing anything. If the warning message just started, then it is likely that the error reporting level or display errors setting was recently changed in php so that you are now seeing an error that was occurring all along.

Link to comment
Share on other sites

Double checked my error reporting, it hasn't changed at all (seeing how that it is hard-coded into the php file).

 

Is there a way to fool the server into letting me use this function by creating a non-obtrusive mysql connection? Such as, if I don't want the connection to be open to anything other than for it to exist so I can use that function... o_O

Link to comment
Share on other sites

I wanted to use the mysql_real_escape_string() as I use it to validate user input for logging in

 

The mysql_real_escape_string() function only escapes special characters so that they can be inserted in to a database query and it prevents sql injection by preventing special characters from being operated on in a query. It has nothing to do with validating user input.

Link to comment
Share on other sites

I'm using it as a string cleaner because at one point in the script, the server calls the username/password combination to store in it's database along with it's IP address. So, I match it against the hard-coded username/password and then randomly save the user's "online status" as a means of tracking. So, just bad grammar, I meant to say string cleaner o_o

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.