I'm having trouble trying to pass the result of mysqli_query to globals because I can only print on the screen the data in the first row of the table. Here is the code:
function of
class
responsible for select:
public function select($dataset_name,$entire = True){
$table = $this->get_table();
$db_connection = $this->get_db_connection();
if ($entire == True) {
$GLOBALS[$dataset_name] = mysqli_query($db_connection,"SELECT * FROM {$table}");
}else {
$array = func_get_args();
unset($array [0]);
unset($array [1]);
$columns = implode(",", $array);
$GLOBALS[$dataset_name] = mysqli_query($db_connection,"SELECT {$columns} FROM {$table}");
}
}
function responsible for printing the result (PS: It is unfinished, since it is not necessary to format the data in a table)
<?php
function list_dataset($dataset_name){
$num_columns = mysqli_field_count($GLOBALS['connection']) - 1;
$count = 0;
while ($array = mysqli_fetch_array($GLOBALS[$dataset_name])) {
while ($count <= $num_columns ) {
echo $array[$count].'</br>';
$count = $count + 1;
}
}
}
?>
The result of entering% with% before function
print_r(array_keys($GLOBALS)); exit;
is:
Array ( [0] => _GET [1] => _POST [2] => _COOKIE [3] => _FILES [4] => GLOBALS [5] => db_connection [6] => db_action [7] => mysqli [8] => connection [9] => con [10] => teste [11] => select )
More information:
-
mysqli_fetch_array()
and$GLOBALS['connection']
coincide, since only a connection was made. -
The function
$GLOBALS[$dataset_name]
has to fit anylist_dataset()
, otherwise it loses its meaning completely. -
I call functions like this:
$db_connection = new db_connection; $db_connection->set_all('localhost','usuário','senha','db'); $db_connection->open(); $db_action = new db_action; $db_action->set_all('tabela_usuarios'); $db_action->select('teste'); $db_action->list_dataset('teste');
Doubt: What am I doing wrong? Am I putting any part of the code in the wrong place?