kratsg Posted February 27, 2008 Share Posted February 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 27, 2008 Share Posted February 27, 2008 As it says, it can't connect to the DB. Where is your connection code? Quote Link to comment Share on other sites More sharing options...
poirot Posted February 27, 2008 Share Posted February 27, 2008 Apparently connection to the DB is failing. Try this: http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html Quote Link to comment Share on other sites More sharing options...
kratsg Posted February 28, 2008 Author Share Posted February 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2008 Share Posted February 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
kratsg Posted February 28, 2008 Author Share Posted February 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
premiso Posted February 28, 2008 Share Posted February 28, 2008 There is no way other than to create a connection. If you goto the php.net site for mysql_real_escape_string people tried to mimic this function, however reports have stated that it does not work nearly as well. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 29, 2008 Share Posted February 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
kratsg Posted February 29, 2008 Author Share Posted February 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.