/**
*author:田元
*
*company:whu eis
*contact:tianyuan168326@outlook.com
*
**/
从重装数据库开始:
软件版本:php 5.5.0 /mysql 5.0.1
安装平台:微软web程序安装平台
问题所在
php code
{
$sqliconnect=new mysqli("localhost","root","52ziji","test");
$query_result=$sqliconnect->prepare("select * from currentorder");
}
“Connect failed: Access denied for user 'root'@'localhost' (using password: YES)” from php function
解决方法:<1>猜测为权限不足,经过*,大体为一个解决方法(eg:https://*.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes):
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' ;
mysql>flush privileges;
即赋全部权限。
经实验,问题未得到解决;
<2>直接清空root密码(eg:https://*.com/questions/11223235/mysql-root-access-from-all-hosts):
mysql>update user set host='localhost' where user='root';
提示未选择数据表
mysql>use mysql;
再次执行,命令成功;
更新phpcode
{
$sqliconnect=new mysqli("localhost","test");
$query_result=$sqliconnect->prepare("select * from currentorder");
}
打印出的连接信息正常,出现新问题:$query_result打印出的信息为 BOOL(FALSE);
解决方法:在*也发现此类问题(eg:https://*.com/questions/8702241/mysqli-prepared-statement-returning-false)
根据don4of4网友回答,加入错误控制:
更新phpcode
{
if(!$query_result)
{
die("result erro:".$sqliconnect->error);
}
}
打印出的错误为 didn't select database;
于是参考官方手册(eg:http://php.net/manual/en/class.mysqli.php)
mysqli->select_db可以手动选择数据库;
更新phpcode{
$sqliconnect=new mysqli("localhost","test");
$sqliconnect->select_db("test");
}
调试信息出现了久违的object(mysqli_stmt)
至此,问题得到完整解决。
ps:我再进行mysqli的__construct()的时候已经传入了db_name,为何不起作用呢?
相关文章
- 连接本地数据库出现:1045 - Access denied for user 'root'@localhost'(using password:YES) 本人解决方案:
- 关于Navicat mysql连接出现1045 access denied for user 'root'@'localhost' using password: yes
- 解决Navicat连接的时候出现了1045 -Access denied for user'root'@'192.168.37.2'(using password :yes)
- MySQL在登陆时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)错误
- phpMyAdmin 升级后出现 #1045 错误 Access denied for user 'root'@'localhost' (using password: YES)
- 使用dbcp出现 Access denied for user 'root'@'localhost' (using password:YES) 的解决办法
- windows XP中,mysql连接时提示:1045 access denied for user 'root'@'localhost' using password yes 的解决方法
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)的一种解决方法
- mac os x 安装mysql遇到 Access denied for user 'root'@'localhost' (using password: YES)的解决方法
- wamp中的phpmyadmin打开出现:#1045 - Access denied for user 'root'@'localhost' (using password: NO)