Warning: MySQLi_Query() Expects Parameter 1 to Be MySQLi, String Given In

How to fix: Warning: mysqli_query() expects parameter 1 to be mysqli?

$link = mysqli_connect($DB_HOST, $user, $pass, $dbName);

mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');

With mysqli you need to save the connection in variable and provide that for every time you use mysqli.

EDIT: generally: You need to provide the connection for every mysqli-related function you use.

mysqli_query() expects parameter 1 to be mysqli, string given in

Modify your db connect class to maintain the connection:

class DB_CONNECT {

protected $connection = null;

// constructor
function __construct() {
// connecting to database
$this->connection = $this->connect();
}

// destructor
function __destruct() {
// closing db connection
$this->close();
}

/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';

// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_error());

// Selecing database
$db = mysqli_select_db($con,DB_DATABASE) or die(mysqli_error()) or die(mysqli_error());

// returing connection cursor
return $con;
}

public function getConnection() {
return $this->connection;
}

/**
* Function to close db connection
*/
function close() {
// closing db connection

}

}

Then modify your query line to:

if (mysqli_query($db->getConnection(), $result)) {


Related Topics



Leave a reply



Submit