PHP - Expect Paramenter

Go To StackoverFlow.com

0

I have been looking at this error for days and I do cannot not find the error.

I know it is not standard practice to place your log on info in the database. I would typically use an include. I will change when I get the error figured out.

The exact error is: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/mjcrawle/class/database.class.php on line 27 Sorry unable to connect:

I have a comment //this is line 26 for the exact location of the error

My database file is...

<?php

// Database Class
    class Database {
        /* Attributes */
        private $host = 'localhost';
        private $database = 'xxxxxxxxxxxxxx';
        private $username = 'xxxxxxxxxxx';
        private $password = 'xxxxxxxxxx';
        public $connection; 

        /*Connection functions*/
        function __construct(){
            $this->db_connect();
        } //ends constructor

        /*Destructor function*/
        function __destruct() {
        } //ends destructor

        public function db_connect() {

            /*Connection to the DB*/
            $conn = mysqli_connect($this->host, $this->username, $this->password)
                    or die("Sorry unable to connect: " . mysqli_error()); //Connects to server

/This is line 26/

mysqli_select_db($conn, $this->database)
                        or die("Sorry unable to connect: " . mysqli_error()); //Connect to database

            $this->connection = $conn;
        }

        /*Query the database*/
        public function db_query($query){


        $result = mysqli_query($this->connection, $query);

        return $result;
        }

    } //End database class


?>
2012-04-04 23:49
by Michael Crawley


4

http://php.net/manual/en/mysqli.error.php

mysqli_error needs the link passed to it

mysqli_error($conn)

i believe

2012-04-04 23:52
by Ascherer
beat me to it +1 : - AlienWebguy 2012-04-04 23:53
tho i gotta say, i suggest PDO instead of mysql or mysqli function - Ascherer 2012-04-05 00:00
Thanks for the uncalled for random downvote... - Ascherer 2012-11-16 17:31
Ads