Hi, I'm making a custom user management class that inherits from DBManager class. The problem I have so far is executing queries using mysqli prepared statements. DB connects fine but then prepare statement fails. I have mysqli object as an attribute that is shared in the class. I'm new with this mysqli (all the times I used normal mysql). Below is the constructor and insertusers method that fails.
Thanks

<?php

protected  $dbLink;
protected  $errorMsg = array();//Inherited by other functions

public function __construct() {
$this->dbLink = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
    $this->addError(mysqli_connect_error());
}
}

public  function insertUsers($arrayofValues) {
        //for inserting users in the database
        $sql = "INSERT INTO users(firstname, lastname, email, username, password) VALUES(?, ?, ?, ?, ?";
        if( $stmt = $this->dbLink->prepare($sql)) {
            $type = array("sssss");
            $params = array_merge($type, $arrayofValues);
            call_user_func_array(array($stmt, 'bind_param'), $this->refValues($params));
            $stmt->execute();
            
            if($stmt==-1) {
                //query failed
                $this->addError(mysqli_connect_error());
                return false;
            }else {
                return true;
            }
        }
        else{
            $this->addError("Something went wrong before InsertUsers stmt could execute well");
        }
    }
?>

Custom? What really means custom … that you programmed a bit … Where is the class definition are you trying to programming OOP without even read the basics ( one page …. 5 minutes your try more than 5 and this post 10) waste of time … isn’t it ?

Custom? What really means custom … that you programmed a bit … Where is the class definition are you trying to programming OOP without even read the basics ( one page …. 5 minutes your try more than 5 and this post 10) waste of time … isn’t it ?

I forgive you because you don't know what and who you are talking to :)
I think you were too swift to read this:
Below is the constructor and insertusers method that fails.

So No class no what. Just information, minimal for my question!
BTW I have been into OOP for a time now doing it in Major languages: Python, PHP, C++, Java et al
Got it now?

you don't know what and who you are talking to... I am talking to a person who has a question and don’t provided the class. "Below is the constructor and insertusers method that fails". (where below ... maybe its me ... but I can't see it ... if you refer to stackoverflow it in not here). Anyhow if you really have any question about your class provide your code to us and what the expected behaviour could be. There is a joke in my neighbour (do you know who are you talking with ?). We are just people (programmers) that ask and answer.. nothing more than that...

Hahahaaa! My Question is already answered (Can't believe you didn't saw it :))
Anyway the problem was not with whole class and I cannot see the reason to post the whole long thing.
Thanks for the post anyway....keeping DW alive :)

On another note,

...if($stmt==-1) {...

when will that be true? prepare() and execute() methods return FALSE upon failure. If you are relying on FALSE to be defined as -1, that may not be a good idea. I suggest you consider revising that statement.

Regards,
Hielo

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.