Hi Daniweb,I'm trying to modify and upgarde My codes from Native mysql to mysqli.
My trail seems to be somehow good as I got My hands with the Php Manual Documentation so forth.
The Only point I got stuck is where I implimented the mysql's mysql_affeted_rows() and so changed it to mysqli and used an Object to refference it $Query->affected_rows but it gives Me No affetceted rows.But when I use the native way the code get to execute fine.
Here is what I have in class_connection.php

<?php

class Database_Connection
    {

        public $Error_Message;
        private $Host,$Username,$Password,$dbName;

        public function Database_Connect()
        {
            $this->Host="localhost";
            $this->Username="root";
            $this->Password="";
            $this->dbName="MydbName";

            $Connector=@mysqli_connect($this->Host,$this->Username,$this->Password,$this->dbName);

            if(mysqli_connect_errno())
            {
            $this->Error_Message="<br/><br/><div class='error'>Please try again Later</div>";
            die($this->Error_Message);
            }
            else
            {
            //This is the handle I'll be needing to accomplish MySqli method calling
            return $Connector;
            }

        }
    }
?>

And in the other file class_login I have this code

<?php
    include("class_connection.php");

class User_Login
    {
    //This Function will be instantiating My Link and returns its Handle whenever called
    protected function MySqli_Instantiator()
        {
        $Connector=new Securities_Set();
        return $Connector->Database_Connect();
        }
    //Not to Worry about this being private there is a Public Function to invoke it 
    private function Login_Tracker($idLogin)
    {
    $Login_Date=date("Y-m-d");
    $Login_Time=date("H:i:s");
    $Logout_Time="00:00:00";

    //Calling this so as to have the DB Link handle
    $MySqli=$this->MySqli_Instantiator();

    $Sql="INSERT INTO login_tracker (idLogin,Login_Date,Login_Time,Logout_Time)
          VALUES(".$idLogin.",'".$Login_Date."','".$Login_Time."','".$Logout_Time."')";
    $Query=$MySqli->query($Sql);
    //Here is where I wonder whats wrong that I cant get it working when use OOP of mysqli style?
    $dbRows_Affected=$Query->affected_rows;

        if($dbRows_Affected!=0 && $dbRows_Affected!=-1)
            {
            $this->Registered_Username($MySqli,$idLogin);
            }
        //I Only get to execute this statement here
        elseif($dbRows_Affected==0)
            {
            $this->Error_Message="<div class='info'>Sorry,the System can not give You the Authentications for now as there Seems to be some Technical issue going on wait and try again afterwards.</div>";
            }
        elseif($dbRows_Affected==-1)
            {
            $this->Error_Message="<div class='error'>Sorry,there seems to be a Problem to Login please try again in few Minutes afterwards.</div>";
            }
    }
    }   
?>

I decided to find some resources more online but This Link seems to prove Me no wrong to My understanding.Any help please?...

Recommended Answers

All 2 Replies

$Connector=@mysqli_connect($this->Host,$this->Username,$this->Password,$this->dbName);

That is procedural style. If you want to use $Query->affected_rows; you'll need to use:

$Connector = new mysqli($this->Host, $this->Username, $this->Password, $this->dbName);

Thak You pritaes that went right,though I had to change some codes as well and got My hands on how to use prepare statement after search for solution and I got interested here and the new codes become ike this for class_connection.php:

    <?php
    class Database_Connection
    {
    public $Error_Message;
    private $Host,$Username,$Password,$dbName;
    public function Database_Connect()
    {
    $this->Host="localhost";
    $this->Username="root";
    $this->Password="";
    $this->dbName="MydbName";
    $Connector=new mysqli($this->Host,$this->Username,$this->Password,$this->dbName);
    if(mysqli_connect_errno())
    {
    $this->Error_Message="<br/><br/><div class='error'>Please try again Later</div>";
    die($this->Error_Message);
    }
    else
    {
    //This is the handle I'll be needing to accomplish MySqli method calling
    return $Connector;
    }
    }
    }
    ?>

And I changed class_login.php to this:

    <?php
    include("class_connection.php");
    class User_Login
    {
    //This Function will be instantiating My Link and returns its Handle whenever called
    protected function MySqli_Instantiator()
    {
    $Connector=new Securities_Set();
    return $Connector->Database_Connect();
    }
    //Not to Worry about this being private there is a Public Function to invoke it
    private function Login_Tracker($idLogin)
    {
    $Login_Date=date("Y-m-d");
    $Login_Time=date("H:i:s");
    $Logout_Time="00:00:00";
    //Calling this so as to have the DB Link handle
    $MySqli=$this->MySqli_Instantiator();
    $Sql="INSERT INTO login_tracker (idLogin,Login_Date,Login_Time,Logout_Time,Device) VALUES(?,?,?,?,?)";
    $Query=$MySqli->prepare($Sql);
    /* BINDING PARAMENETRS PASSED IN AN SQL ON THE VALUES() MARKES=?,NOTE THAT:(s = string, i = integer, d = double,  b = blob) */
    $Query->bind_param("issss",$idLogin,$Login_Date,$Login_Time,$Logout_Time,$Device_Information);
    $Query->execute();

    //AND AVERITHING PASSED FINE TO Registered_Username($MySqli,$idLogin)
    if($dbRows_Affected!=0 && $dbRows_Affected!=-1)
    {
    $this->Registered_Username($MySqli,$idLogin);
    }
    elseif($dbRows_Affected==0)
    {
    $this->Error_Message="<div class='info'>Sorry,the System can not give You the Authentications for now as there Seems to be some Technical issue going on wait and try again afterwards.</div>";
    }
    elseif($dbRows_Affected==-1)
    {
    $this->Error_Message="<div class='error'>Sorry,there seems to be a Problem to Login please try again in few Minutes afterwards.</div>";
    }
    }
    }
    ?>

Thanks a Lot for Your Help pritaeas I hope soon I'll be on MySqli OOP as sure it have some tricks I must admit but if I just do more readings and so its all related to OOP php skilss that I have a litle.

Be a part of the DaniWeb community

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