php - fetching data from mysqli -


i've been getting issue message can't seem figure out reason ,"mysqli_query() expects parameter 1 mysqli" here's code (i have object called database aside repsonsable db connection , other db function);

 <?php        $sql="select marque,cpu pc";        if ($result=mysqli_query($database->connection,$sql))       {           // fetch 1 , 1 row            while ($row=mysqli_fetch_row($result))             { printf ("%s %s\n",$row[0],$row[1]);             }             // free result set             mysqli_free_result($result);                }?> 

and here part co.php responsable db connection

enter code here        class mysqldatabase {        public $connection;        public function open_conection(){        $connection=mysqli_connect('localhost', 'root', '', 'alpha');         if (!$connection){          die ("can't connect:".mysqli_error());     }else {      $select_db=mysqli_select_db($connection,'alpha');     if(!$select_db) {         die ('no database:' .mysqli_error());  }  } } } 

change class this:

class mysqldatabase{      private $connection;      public function __construct(){         $this->connection = mysqli_connect('localhost', 'root', '', 'alpha');         if (!$connection){die ("can't connect:".mysqli_error())};     }      public function  get_connection(){         return $this->connection;     } } 

use this:

<?php   include 'mysqldatabase.php';  $db = new mysqldatabase(); $conn = $db->get_connection();  $sql="select marque,cpu pc"; if ($result=mysqli_query($conn,$sql)){     // fetch 1 , 1 row     while ($row=mysqli_fetch_row($result))     {          printf ("%s %s\n",$row[0],$row[1]);     }     // free result set     mysqli_free_result($result); }else{     echo 'query failed'; } ?> 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

c - getting error: cannot take the address of an rvalue of type 'int' -

How to merge four videos on one screen with ffmpeg -