duanqujing3863 2016-03-17 15:52
浏览 32

PHP没有从网上看到mysql.sock

I have a script that connects to a MySQL database in localhost, when I run it from the console it runs just fine, but when I run it from the web, I get this:

Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/tests/mysql.php on line 3

Error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory

I checked my php.ini file and it has the correct location of mysql.sock, the file exist, but php won't connect via web.

Also, I have Fedora Linux with Firewall disabled as well as SELinux, so I have no idea what can be causing this.

This is the test code I'm using:

<?php
$link = mysqli_connect("localhost", "root", "password", "my_db");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);
?>

Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试