mysql_real_escape string errors

北城以北 提交于 2019-12-13 03:56:55

问题


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?


回答1:


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




回答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!




回答3:


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.




回答4:


check your db settings inside..

application>config>database.php


来源:https://stackoverflow.com/questions/13602286/mysql-real-escape-string-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!