php从文件中读取出的用户名不能用于连接数据库

choas_yuan 2015-01-22 10:29:59
$this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd) ;
if ( !($this->conn) )
{
die('Could not connect:'.mydsql_error('连接出错')) ;
}
echo '连接成功!<br>';
$this->db_host, $this->db_user, $this->db_pwd 都是从.ini文件中取值,取出来的值中主机地址和密码都可以用,但用户名却不能,如果是直接将用户名的字符串连接 mysql 就不会出错,如果是从文件中取出的用户名用于连接就会出现错误,如下:
Warning: mysql_connect(): Access denied for user 'noco '@'14.210.115.31' (using password: YES) in C:\xampp\htdocs\projects\ship_thing_swap\mysql\connection.php on line 52

Fatal error: Call to undefined function mydsql_error() in C:\xampp\htdocs\projects\ship_thing_swap\mysql\connection.php on line 55
请教各路大神这是神马情况???
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2015-01-23
  • 打赏
  • 举报
回复
观察到 'noco '@'14.210.115.31' 和 'noco'@'14.210.115.31' 的区别 显然是多了空格、回车、换行之类的字符 你是怎么读取 ini 文件的?
事故的故事 2015-01-23
  • 打赏
  • 举报
回复
$this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd) ; if ( !($this->conn) ) { die('Could not connect:'.mydsql_error('连接出错')) ; } 拼写错误
一起混吧 2015-01-23
  • 打赏
  • 举报
回复
显然 'noco '@'14.210.115.31' 用户名后面多了个空格。
xuzuning 2015-01-23
  • 打赏
  • 举报
回复
那是要去掉尾部的空白字符的(空格、回车、换行)
$this->db_host = trim(fgets($openfile)) ;
$this->db_user = trim(fgets($openfile)) ;
$this->db_pwd = trim(fgets($openfile)) ;
choas_yuan 2015-01-23
  • 打赏
  • 举报
回复
读取文件方式: $this->db_host = fgets($openfile) ; $this->db_user = fgets($openfile) ; $this->db_pwd = fgets($openfile) ;

21,892

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧