使用php将在线mysql数据库与本地xampp服务器连接 [英] Connect online mysql database with the local xampp server using php

查看:182
本文介绍了使用php将在线mysql数据库与本地xampp服务器连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在php中使用以下代码:

  <?php 
$ servername = www。 psgcirdask.com;
$ username = xxx; //出于安全目的而被隐藏
$ password = password;
$ dbname = psgcilqh_calibration;
//创建连接
$ conn = new mysqli($ servername,$ username,$ password,$ dbname);
//检查连接
是否($ conn-> connect_error){
die(连接失败:。$ conn-> connect_error);
}

$ sql =选择*来自品牌;
$ result = $ conn-> query($ sql);
$ conn-> close();
?>

我遇到错误:


警告:mysqli :: __ construct():(HY000 / 1045):在C:\xampp\htdocs\中拒绝访问用户'xxx'@'157.51.147.43'(使用密码:是)第9行
中的 justshawarmapos checkthedatabase.php连接失败:用户'xxx'@'157.51.147.43'的访问被拒绝(使用密码:是)


但是我使用相同的用户名和密码连接到我的网站中的数据库。只有在使用本地服务器连接时,我才遇到此问题。

解决方案

您必须在mysql数据库中启用远程访问。



检查此 $ href = https://youtu.be/xXOq9U9fzOo rel = nofollow noreferrer> hostgator


I tried using the following code in php:

<?php
$servername = "www.psgcirdask.com";
$username = "xxx"; //hidden for security purpose
$password = "password";
$dbname = "psgcilqh_calibration";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
 // Check connection
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

  $sql = "SELECT * FROM brands";
  $result = $conn->query($sql);
$conn->close();
?>

I got an error:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'xxx'@'157.51.147.43' (using password: YES) in C:\xampp\htdocs\justshawarmapos\checkthedatabase.php on line 9 Connection failed: Access denied for user 'xxx'@'157.51.147.43' (using password: YES)

But i use the same username and password to connect to my database in my website.I am getting this problem only when i connect using local server.

解决方案

You have to enable remote access in your mysql database.

Check this link

For hostgator

这篇关于使用php将在线mysql数据库与本地xampp服务器连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆