duanju7199 2012-07-08 01:58
浏览 141

PHP MYSQL无法连接(HY000 / 2002)[关闭]

i was working on a website on a local server (WAMP) and php and database worked fine. but when i uploaded the site to the hosting server. and tried to login, the DB connection would not work. it gives me warnings when i use DB functions like mysqli::mysqli().

the whole error is as follows:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): No connection could be made
because the target machine actively refused it. 
in D:\Hosting\XXXXX\htmlaw\database\connect.php on line 9

continues

Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] No connection could be made because
the target machine actively (trying to connect via tcp://localhost:3306) in     
D:\Hosting\XXXXX\htmlaw\database\connect.php on line 9


Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in    
D:\Hosting\XXXXX\htmlaw\functions\users.php on line 10

The php code for connect.php is:

<?php

    require_once 'Internal/Var.php';
    //mysql_connect(D_SERVER, D_USER, D_PASSWORD);
    //mysql_select_db(D_NAME);

    function create_connection()
    {
        $conn = new mysqli(D_SERVER, D_USER, D_PASSWORD, D_NAME);
        return $conn;
    }

    function close_connection(mysqli $con)
    {
        $con->close();
    }

?>
  • 写回答

1条回答 默认 最新

  • drozwmi5440 2012-07-08 02:00
    关注

    You need to specify the username and password for your MySQLi connection.

    require_once 'Internal/Var.php';
    // Remove the two procedural connection lines here
    
    function create_connection()
    {
        // Make sure D_SERVER, D_USER, D_PASSWORD, D_NAME have the correct values
        // These values are probably created in Internal/Var.php
        $conn = new mysqli(D_SERVER, D_USER, D_PASSWORD, D_NAME);
    
        return $conn;
    }
    
    function close_connection(mysqli $con)
    {
        $con->close();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突