hello there - been awhile since ive been about but im ready to crack on with my learning :)

kk i used to have this installed on my last "free" host and it worked fine
now im on a paid host (hosting24) it doesnt seem to want to work correctly..

kk i got my db back up and files backed up
i then proceeded to alter db connection details in all the files that needed it - uploaded all the files and imported my database...

now when i load my main page is get the following:

Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /home/daztestc/public_html/design/users/class.Logare.php on line 64

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in /home/daztestc/public_html/design/users/class.Logare.php on line 66

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in /home/daztestc/public_html/design/users/class.Logare.php on line 265

i have double checked and then triple checked the exact spelling and password for the database but still refuses to connect. ive asked my host if all the required extensions are activated on my package and they confirmed they are - they even had a look at the files but as it wasnt a fault there end im left on a cold step now lol

lines 63-67 :

    // if the connection is successfully established
    if($conn = new mysqli($this->conn_datas['localhost'], $this->conn_datas['daztestc_testdaz'], $this->conn_datas['dj2403ms81'], $this->conn_datas['daztestc_daztest'])) {
      $sql = "SET NAMES 'utf8'";
      $this->conn = $conn;          // add the connection in the $conn property

and lines 263-269 :

      // if 0 returned rows, perform another Select for total users (when 'useron' is empty, the "nrusers" also returns 0)
      $sql = "SELECT `nume` AS last, (SELECT count(*) FROM `users`) AS nrusers FROM `users` WHERE `rank`>0 ORDER BY `id` DESC LIMIT 1";
      $result = $this->conn->query($sql);
      if($result->num_rows>0) {
        $rand = $result->fetch_assoc();
        $re['total'] = $rand['nrusers'];
        $re['last'] = '<a href="'.$this->dir.$this->file_log.'?usr='.$rand['last'].'" title="'.$rand['last'].'">'.$rand['last'].'</a>';

does anybody have a suggestion on where i would go next in order to work towards sorting this problem please?
sorry if ive posted this wrong in anyway - it has been awhile i must admit..
any other info you might require just let me know :D
thanks in advance DaniWeb ;)

Recommended Answers

All 5 Replies

the error you are seeing is relating to the login details/access rights.

Is the DB user you are using got access rights to the database it self?

thanks for the reply squidge

yes the user has full privilages and rights to the database. I set these when i created the user for the database


This appears wrong. Can you show how you defined your conn_datas array?

yh sure - the follwing is lines 1-72

// Logare class Logare
class Logare {
  // properties
  protected $conn = false;           // store the connection to mysql
  protected $conn_datas = array();    // will contain the data for connecting to mysql
  protected $sid;                   // for the session ID
  protected $nr_logs = 1;            // for the current number of login attempts
  public $users = array();           // will store the total users, last registered, and online users
  protected $eror = false;          // to store the errors
  protected $ip;                    // for the user IP (the IP saved in cookie or the current IP)
  public $dir = 'users/';          // the directory that contains the classes for this script
  protected $file_log = 'index.php';   // the file in which the instances of the classes are created
  public $logat = '';               // stores the login form or the "Welcome" message
  public $js = '';                 // for the code that include the file with JavaScript functions

  // constructor
  public function __construct($conn_datas) {
    // daca parametrul e array
    if(is_array($conn_datas)) {
      $this->conn_datas = $conn_datas;        // add data from parameter in 'conn_datas' property
      $this->sid = session_id();             // add the session ID in $sid property

      // define the $js property
      $this->js = '<script src="'. $this->dir. 'logare.js" type="text/javascript"></script>';

      // if no $_POST['ajax'], define the login form in "logat" property
      if(!isset($_POST['ajax'])) $this->logat = '<form action="" method="post" id="log_form"> Name: &nbsp; &nbsp; &nbsp; <input type="text" name="nume" id="nume" size="12" maxlength="30" /> &nbsp; <input type="submit" name="login"  class="submit" value="Login" /><br /> Password: <input type="password" name="pass" id="pass" size="11" maxlength="30" /> <label for="rem" id="lrem"><input type="checkbox" name="rem" id="rem" />Remember</label><br/><br/>
  <a href="'. $this->dir.$this->file_log. '?rc=Recover" title="Recover data" id="recdat">Recover data</a>
  <span id="log_reg"><a href="'. $this->dir.$this->file_log. '?submit=Register" title="Register" id="linkreg">Register</a></span></form>'.$this->js;

      // if $_COOKIE['ip'] exists, get the IP from cookie, else, get the current IP and save it in cookie
      if(isset($_COOKIE['ip'])) $this->ip = $_COOKIE['ip'];
      else {
        $this->ip = $_SERVER['REMOTE_ADDR'];
        setcookie("ip", $this->ip, time()+60*60*24*100, "/");

      $this->setConn();       // calls setConn() method (that sets the mysql connection)

      // if the connection to database is set ('conn' property isn't false)
      if($this->conn!==false) {
        // if there is data from the login form, calls the getLogin() method
        if(isset($_POST['login']) && isset($_POST['nume']) && isset($_POST['pass'])) {
          $_POST = array_map("trim", $_POST);        // removes whitespace from the beginning and end
        // if request for logout ($_GET['lout']), calls logOut() method
        else if(isset($_GET['lout'])) $this->logOut();
        else $this->setLogat();        // else, calls setLogat() method that sets the $logat property

        if($this->nr_logs>1) $this->logOut(2);        // $nr_logs>1 means two logins with the same name. Logout the user
    else $this->eror = 'The argument for class instance must be an Array';

    // if $eror property isn't false, add it in $logat property
    if($this->eror!==false) $this->logat = '<div id="logeror">'.$this->eror. '</div>'. $this->logat;

  // method that create the connection to mysql
  public function setConn() {
    // if the connection is successfully established
    if($conn = new mysqli($this->conn_datas['localhost'], $this->conn_datas['daztestc_testdaz'], $this->conn_datas['dj2403ms81'], $this->conn_datas['daztestc_daztest'])) {
      $sql = "SET NAMES 'utf8'";
      $this->conn = $conn;          // add the connection in the $conn property
    else if (mysqli_connect_errno()) $this->eror = 'MySQL connection failed: '. mysqli_connect_error();
    return $this->conn;

Show your code that initializes that array, and passes it to the constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.