Bonfim Junior
Bonfim Junior

Reputation: 5

Error Warning: mysqli::mysqli() expects parameter 2 to be string, object given in

I am having this error on that 60 line in connection with mysqli. I've tried some modifica- tions but have not been successful.

ERROR: Warning: mysqli::mysqli() expects parameter 2 to be string, object given in

<?php

    class KT_Connection {

        /**
         * The database name
         * @var string
         * @access private
         */
        var $databaseName = '';

        /**
         * The connection Resource ID
         * @var object ResourceID
         * @access private
         */
        var $connection = null;

        /**
         * Flag. what server model is.
         * @var string
         * @access private
         */
        var $servermodel = "mysql";

        /**
         * for ADODB compatibility
         * @var string
         * @access public
         */
        var $databaseType = "mysql";

        /**
         * The constructor
         * Sets the connection and the database name
         * @param object ResourceID &$connection
         * @param string $databasename
         * @access public
         */
        function KT_Connection(&$connection, $databasename) {
            $this->connection = &$connection;
            $this->databaseName = $databasename;
        }

        /**
         * Executes a SQL statement
         * @param string $sql
         * @return object unknown
         *         true on success
         *         response Resource ID if one is returned by the wrapper function
         * @access public
         */
        function Execute($sql) {
            if (!mysqli_select_db($this->databaseName, $this->connection)) {
                return false;
            }           
            $response = mysqli_query($sql, $this->connection);
            if (!is_resource($response)) {
                return $response;
            } else {
                $recordset = new KT_Recordset($response);
                return $recordset;
            }
        }

        /**
         * Executes a SQL statement
         * @param string $sql
         * @return mysql resource
         *         true on success
         *         response MYSQL Resource ID
         * @access public
         */
        function MySQL_Execute($sql) {
            if (!mysqli_select_db($this->databaseName, $this->connection)) {
                return false;
            }   
            $response = mysqli_query($sql, $this->connection);
            return $response;
        }

        /**
         * Gets the error message
         * @return string
         * @access public
         */
        function ErrorMsg() {
            return mysqli_error($this->connection);
        }

        /**
         * Gets the auto-generated inserted id (if any)
         * @return object unknown
         * @access public
         */
        function Insert_ID($table, $pKeyCol) {
            return mysqli_insert_id($this->connection);
        }
    }
    ?>

Upvotes: 0

Views: 758

Answers (2)

hassan
hassan

Reputation: 8288

The problem is in your connection establishing,

according to php manual mysqli_select_db

bool mysqli_select_db ( mysqli $link , string $dbname )

Parameters ¶

link

Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init() dbname

The database name.

you have reversed the parameters which passed to mysqli_select_db function as follows :

mysqli_select_db($this->databaseName, $this->connection)

while it have to be as follow:

mysqli_select_db($this->connection, $this->databaseName)

Upvotes: 1

P. Gearman
P. Gearman

Reputation: 1166

You have

$response = mysqli_query($sql, $this->connection);

I believe this needs to be

$response = mysqli_query($this->connection, $sql);

Upvotes: 1

Related Questions