【发布时间】:2015-03-06 21:03:51
【问题描述】:
我使用hostgator 来托管我的网站,并且我已将IP 地址添加为远程访问主机。然后我连接了 mySql 工作台并测试了连接,我得到了所有参数都正确的消息。在 hostgator 上,我将自己添加为管理员用户,授予自己所有权限。现在我想使用 PDO 通过 PHP 脚本操作数据库,但这是我在尝试运行 PHP 文件时在浏览器中遇到的错误:
连接失败:SQLSTATE[28000] [1045] Access denied for user 'user'@'host' (using password: YES)
在 mySQL 工作台用户和权限选项卡上,我得到了这个:
“The account you are currently using does not have sufficient privileges to make changes to MySQL users and privileges.”
我不确定这里出了什么问题,我对此很陌生。有人可以帮忙吗?
编辑:
php 代码如下:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
//this block tries to connect to the database
//if there's an error connecting, the code under catch will
//and the program will end
$host="host";
$port="3306";
$user="xxx";
$password="xxx";
$dbname="database";
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname;", $user, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
//$con->close();
?>
【问题讨论】:
-
使用用户名和密码可以通过shell成功登录吗?
-
您必须在此处发布您的
php代码 -
我查看了这篇帖子link,奇怪的是我什至没有一个 usr 目录来存放这个文件。所以不幸的是SSH连接失败。 @sanojlawrence 我编辑了我的主线程以包含 php 代码
-
@rads89 你不得不提
$host="localhost"; -
@sanojlawrence 我没有尝试连接到本地主机。我实际上是在尝试连接到我的 hostgator 服务器。为了这篇文章的目的,我刚刚删除了 hostgator 服务器 IP 地址。
标签: php mysql pdo mysql-workbench