0

I've been getting these two error messages. my code is

public function __construct() {

        $db->connect();

    }

    function connect() {

        return  new mysqli('localhost', DB_USER, DB_PASS,DB_NAME);


    }

Does anyone know what my issue is. i am still very new to PHP so sorry if this is a stupid question.

my DB_USER ,DB_PASS, DB_NAME are saved in my config file

2

1 Answer 1

1

You need to use $this -

$this->db->connect();

$db supposed to be a member variable of that class. You can' access $db like that unless you have passed it to the function like -

function your_function($db) {

To access the member variables $this pointer is used, which points to the current instance.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you. tbh i've been trying to use a old open source DB classed that used mysql not mysqli- and just had loads of problems. so think i am going to have to write it all out myself
That will be better to undrstand.
you wouldn't happen to know a good up to date tutorial? my goal is to build a class that connects to the database - using prepared statements inserts - updates - selects- all in a general way so the class can be used in multiple projects. then i want to create two custom classes that call on the methods of the db class to insert /update/select with the unique queries for this application. i've found a few but any recommendation from someone who knows abit more about what there doing. would be greate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.