I'm trying to build a class to be used with mysql at first I have only two files so I'll paste the code I've already done here and explain my doubts.
classes/connect.php
<?php
/**
* Created by PhpStorm.
* User: evtns
* Date: 08/06/2016
* Time: 17:55
*/
class Database
{
private $db_ip = '127.0.0.1';
private $db_user = 'root';
private $db_pass = 'aaxd31mubr';
private $db_select = 'sistema';
public function connet(){
$dbc = mysqli_connect($this->db_ip,$this->db_user,$this->db_pass) or die("falha ao conectar");
if(mysqli_select_db($dbc, $this->db_select ))
{
echo 'DB selecionado com sucesso <br />';
return $dbc;
}
else{
echo 'falhou';
return false;
}
}
public function __construct()
{
}
public function select($cols='*',$tables ,$where=null, $value=null, $order=null)
{
$query = "SELECT $cols ";
$query .="FROM $tables ";
if(isset($where) and isset($value))
{
$query .="WHERE $where='$value'";
echo 'teste 1 ok';
}
if(isset($order))
{
$query .="ORDER BY $order";
}
if($result_query = mysqli_query($this->connet(), $query)){
return $result_query;
}
echo 'Falha ao executar querry da função select.';
return false;
}
}
index.php
<?php
/**
* Created by PhpStorm.
* User: evtns
* Date: 08/06/2016
* Time: 18:33
*/
include_once 'classes/connect.php';
$db = new Database();
//$cols='*',$tables,$where, $state//
$row = mysqli_fetch_array($db->select('*', 'estado'));
print_r(array_count_values($row));
?>
My problem is here I made an instance of the class, but when I try to access the elements of the result_query of public function select, with mysqli_fetch_array (), it only returns me the first element of the database, now if I try directly on the function it returns me all the values registered in the bank.
Does anyone know how to solve this problem?