$this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd) ;
if ( !($this->conn) )
{
die('Could not connect:'.mydsql_error('连接出错')) ;
}
echo '连接成功!
';
$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
请教各路大神这是神马情况???
婚纱影楼小程序提供了一个连接用户与影楼的平台,相当于影楼在微信的官网。它能帮助影楼展示拍摄实力,记录访客数据,宣传优惠活动。使用频率高,方便传播,是影楼在微信端宣传营销的得力助手。功能特点:样片页是影楼展示优秀摄影样片提供给用户欣赏并且吸引客户的。套系页是影楼根据市场需求推出的不同套餐,用户可以按照自己的喜好预定套系。个人中心可以查看用户预约的拍摄计划,也可以获取到影楼的联系方式。
回复讨论(解决方案)
$this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd) ;
if ( !($this->conn) )
{
die('Could not connect:'. mydsql_error('连接出错')) ;
}
拼写错误
观察到
'noco '@'14.210.115.31'
和
'noco'@'14.210.115.31'
的区别
显然是多了空格、回车、换行之类的字符
你是怎么读取 ini 文件的?
读取文件方式:
$this->db_host = fgets($openfile) ;
$this->db_user = fgets($openfile) ;
$this->db_pwd = fgets($openfile) ;
那是要去掉尾部的空白字符的(空格、回车、换行)
$this->db_host = trim(fgets($openfile)) ;$this->db_user = trim(fgets($openfile)) ;$this->db_pwd = trim(fgets($openfile)) ;
显然 'noco '@'14.210.115.31' 用户名后面多了个空格。










