dtoka218420 2018-08-11 15:21
浏览 50

无法连接到'XX.XX.XX.XX'上的MySQL服务器(13)

CentOS+MariaDB+PHP+Nginx

Have a test table in DB, that contain tow strings: 'qwe','asd' 'rty','fgh'

Have a test script, that works if I lounch it from cmd:

$ php test.php test page
qwe - asd
rty - fgh

So, MySQL+PHP works!!!

Have info.php file in the root dir of nginx, that works too (I see page in browser). So, Nginx+PHP works too!!!

But, when I request test.php by http, browser (and curl too) returns that: Can't connect to MySQL server on 'XX.XX.XX.XX' (13)

I have installed LEMP twice with the same result by using this instruction: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

Several hours in internet didn't provide any answers! Thanks for help!

P.S. If someone would like to test, here is scripts:

//Table in DB:
create table a_first (request varchar(30), answer varchar(30)) ;
insert into a_first values ('qwe','asd') ;
insert into a_first values ('rty','fgh') ;

//Contains of /usr/share/php/db.php
$servername="ip_address";
$username="mysql_user";
$password="mysql_pass";
$dbname="dbname" ;

//Contains of /usr/share/nginx/html/test.php
<?php
echo "<html><header></header><body>";
require_once 'db.php';

echo "test page" ;
echo "<br>" ;


$conn = mysql_connect($servername, $username, $password);

if (!$conn) {
    die('cani\'t connect: ' . mysql_error());
}

$db_selected = mysql_select_db($dbname, $conn);
if (!$db_selected) {
    die ('can\'t select DB: ' . mysql_error());
}

$sql = "select * from a_first; " ;
$result = mysql_query($sql);

if (!$result) {
    die('SQL error: ' . mysql_error());
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row['request']." - ".$row['answer']." 
";
    echo "<br>
" ;
}

mysql_free_result($result);

echo "</body></html>";
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?