无法使用php连接到远程数据库
我在Windows中安装了Xampp,并且正在使用Laravel 5.3创建应用程序.我正在尝试在本地网络上的另一台服务器上执行查询,但是当我尝试执行该操作时,MySql服务器对本地服务器上的用户进行身份验证时使用(username: "root" && password:""
),而远程服务器具有(username: "root" && password:"root"
)和i不知道为什么.这是我在config/database.php下的laravel连接
I have Xampp installed in windows and I am creating an application using Laravel 5.3. I am trying to execute a query on another server on local network but when I try to do that the MySql server authenticate the user that is on my local server with is (username: "root" && password:""
) while the remote server have (username: "root" && password:"root"
) and i don't know why. here is my laravel connection under config/database.php
'smsgateway' => [
'driver' => 'mysql',
'host' => '**.**.**.**',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
我如何使用连接
$smsgateway = \DB::connection('smsgateway');
// dd($smsgateway);
$smsgateway->statement($sql);
我尝试使用本地PHP代码进行连接,但是我遇到的问题是我的代码
I tried to connect using a native PHP code but I face the same problem here is my code
$servername = "**.**.**.**;
$username = "root";
$password = "root";
try {
$conn = new PDO("mysql:host=$servername;dbname=database", $username, $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();
}
它给了我
连接失败:SQLSTATE [HY000] [1045]用户的访问被拒绝 'root'@'myIPAddress'(使用密码:是)
Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'root'@'myIPAddress' (using password: YES)
- 您需要授予从本地访问数据库的权限
- 使用这些命令,然后还原,帮助网址在此处 从任何IP地址授予对MySQL数据库的远程访问
- You need to grant the permission to access the database from local
- Use these commands and then revert , help url here grant remote access of MySQL database from any IP address