Is there any idea how to import mysqli connection from the include file?
db_connect.php
<?php
class DB_CONNECT {
/* -- */
function connect() {
require_once __DIR__ . '/db_config.php';
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysqli_connect_error());
$db = mysqli_select_db($con, DB_DATABASE) or die(mysqli_connect_error()) or die(mysqli_connect_error());
return $con;
}
/* -- */
}
index.php
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysqli_query($db, "SELECT *FROM tasks");
If I do this, will get this error message.
Warning: mysqli_query() expects parameter 1 to be mysqli, object given in index.php on line XXX