0

I'm trying to set up a codeigniter web app I just recently finished on a server. I wrote it locally on my own computer. However when I try to login I get these two errors.

A PHP Error was encountered

Severity: Warning

Message: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO)

Filename: mysql/mysql_driver.php

Line Number: 319



A PHP Error was encountered

Severity: Warning

Message: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established

Filename: mysql/mysql_driver.php

Line Number: 319

Anyone know what the problem is?

4
  • Are you connecting to the DB after or before the call to this function? Commented Nov 28, 2012 at 9:54
  • 1
    I'm assuming if you fix your database connection string, this will go away Commented Nov 28, 2012 at 9:54
  • This function uses the last database connection handle/resource, if any, or the one declared in the second parameter of this function. Make sure it's already connected before using this function. Commented Nov 28, 2012 at 9:56
  • The answer to your question is in this post: [stackoverflow.com/questions/1162491/… [1]: stackoverflow.com/questions/1162491/… Commented Nov 28, 2012 at 9:57

4 Answers 4

4

First make sure you are connect to your db

you can modify the settings in application/config/database.php

for codeigniter you should use

$this->db->escape() 

Details and samples can be found here http://ellislab.com/codeigniter/user-guide/database/queries.html

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I'm sure that I'm connected to the DB, I've even autoloaded the database library and I haven't personally used mysql_real_escape_string anywhere in my code. Can't you see that the error is coming from a native CI database driver, not from my own code.
2

I finally found what was causing the problem. It was this line in the database config folder:

$db['mydb']['autoinit'] = FALSE;

When I changed it to :

$db['mydb']['autoinit'] = TRUE;

It worked! Thanks guys for all your advice, wouldn't have done it without you!

Comments

1

The answer is simple: mysql_real_escape_string() (the hint is in the name) escapes a string based on the receiving character set used by the DB connection. In order to use this, you first need to be connected to a MySQL server!

Auto-load the DB class and have it auto-connect. It'll solve your problem.

3 Comments

I've autoloaded the database library and I haven't personally used mysql_real_escape_string anywhere in my code.
Correction to the comment: if you haven't used mysql_real_escape_string at all and don't require DB access, unload the DB connector. It looks like it is trying to connect, fails, and continues as normal. Surely that's an old version of CodeIgniter, for it to do this (and to rely on deprecated functions)...
My eyes just got burned off by the CodeIgniter MySQL driver. I might provide a replacement at some point - this thing runs on ShutOp... no wonder it silently fails to connect. Anyway, if you don't need DB access, un-autoload it. It'll solve your issue. If you need DB access, autoload it and make sure it can connect.
0

check your db settings inside..

application>config>database.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.