PHP Warning: MySQLi_Close() Expects Parameter 1 to Be MySQLi

php warning: mysqli_close() expects parameter 1 to be mysqli

mysqli_close($result);

The line above is incorrect. You only need to call mysqli_close() once (if at all since, as pointed out in the comments, the connection is closed at the end of the execution of your script) and the parameter should be your link identifier, not your query resource.

Remove it.

Warning: mysqli_close() expects parameter 1 to be mysqli

You don't need this line:

mysqli_close($result);

You only need to close the connection.

mysqli_close() expects parameter 1 to be mysqli, null given

Make $con a private variable outside of the function.

<?php

/**
* A class file to connect to database

*/

class DB_CONNECT {

private $con = null;

// constructor
function __construct() {

}

// destructor
function __destruct() {

// closing db connection
$this->con = null;
}

/**
* Function to connect with database

*/
function connect() {

// import database connection variables
require_once __DIR__ . '/db_config.php';

// Connecting to mysql database
$this->con = mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE) or die("Data base connection failed....! " . mysqli_error($con));

// returing connection cursor
return $this->con;
}

/**
* Function to close db connection

*/
function close() {

// closing db connection
mysqli_close($this->con);

}
}
?>

Then you can access it throughout the class. Also in your constructor call the connect function to ensure that the first thing it does is connect.

Edit 1

From what I can see your naming convention is a bit off too. Your class name DB_CONNECT looks like a const because that's how you have specified them in your db_config.php.

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /users/mikadoru/www/register.php on line 16

You are not opening any DB!

From PHP manual:

mysqli_connect($db_host,$db_user,$db_pass,$db_database,$db_port);

mysqli_query() and mysqli_close expects parameter 1 to be mysqli - PHP

$mysqli is not defined anywhere in your first script. It looks like you meant to include the second script at the top of the first one, but you didn't. So do that and your problem will go away.

<?php
session_start();
include("WhateverThatOtherScriptIsCalled.php");
...


Related Topics



Leave a reply



Submit