3

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\html\raw\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\html\raw\database\connect.php on line 9


Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in    
D:\Hosting\XXXXX\html\raw\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();
    }

?>
tereško
  • 58,060
  • 25
  • 98
  • 150
Saad Masood
  • 11,036
  • 9
  • 32
  • 40

1 Answers1

1

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();
}
Vaidas
  • 968
  • 9
  • 22
Aditya M P
  • 5,127
  • 7
  • 41
  • 72
  • the error is abt the DB connection.i am still geting the errors abt DB functions.. – Saad Masood Jul 08 '12 at 02:08
  • After you set those constants like D_SERVER etc., what errors are you seeing? DB connection is the thing I'm trying to fix with my answer. – Aditya M P Jul 08 '12 at 02:11