douyi3833 2018-05-29 19:36
浏览 61

PHP网页没有连接到其他设备上的SQL服务器

I have created a simple php program running on apache2 server, php does work, but it is not connecting to the sql server when I view the file on another device. The database I am using on my Debian 9 device is MariaDB.

<?php
$conn = new mysqli("localhost","root","password","login");
$query = "SELECT * FROM users WHERE username = 'Martin';
$result = $conn->query($query);
$row = $result->fetch_array(MYSQLI_ASSOC);
echo $row['password'];
?>

I am prety sure I got the code right (i have tried mysql_connect and other methods). I dont understand why the webpage is giving me an error when I try and view the page on another device.

The times it worked varied when I was using the Debian device. It would sometimes work, and sometimes not. The tables and database in the sql server is fine, I have checked it over, and I dont think it is a fault with that.

MariaDB [(none)]> select * from login.users;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
|  1 | Martin   | pass     |
+----+----------+----------+
1 row in set (0.01 sec)

MariaDB [(none)]> 

Can someone help me? I think that I have to enable something in apache files but my knowledge is limited and I dont know what kind of problem I am getting.

  • 写回答

1条回答 默认 最新

  • dream_life5200 2018-05-29 19:44
    关注

    Aside from anything else, the following line:

    $query = "SELECT * FROM users WHERE username = 'Martin';
    

    should be

    $query = "SELECT * FROM users WHERE username = 'Martin'"; // add the missing double quote
    

    If that doesn't resolve the issue, you should probably post the error message.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比