0
Hello I’m making a system to search list the data in the database for the month only it give the following error
Fatal error: Uncaught Error: Call to Undefined method mysqli::getInstance()
and in my view it’s all right.
this is the query .
<?php
require('config.php');
class Usuario {
private $connection = null;
public function __construction($connection) {
$this->connection = $connection;
}
public function carregaSetores($data) {
try {
$Query = "SELECT
s.nome,
s.snome,
s.telefone,
s.refeicao,
s.bebida,
s.data,
s.hora,
s.npessoa,
s.nmesa,
FROM pedido
";
$p_sql = mysql::getInstance()->prepare($Query);
$_retorno = array();
if ($p_sql->execute()) {
while ($_result = $p_sql->fetch(PDO::FETCH_ASSOC)) {
$_retorno[] = $_result;
}
}
return $_retorno;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
?>
and this is the code that generates the report.
<?php
require('config.php');
require('usuario.php');
$data = $_POST["data"];
$Usuario = new Usuario($dbConnetion);
$listaDados = $Usuario->carregaSetores($data);
if(!empty($listaDados)){
foreach($listaDados as $value){
//echo "<pre>"; print_r($value); exit;
echo "<tr>";
echo "<td><center>". $value["nome"] ."</center></td>";
echo "<td><center>". $value["snome"] ."</center></td>";
echo "<td><center>". $value["telefone"] ."</center></td>";
echo "<td>". $value["refeicao"] ."</td>";
echo "<td>". $value["bebida"] ."</td>";
echo "<td><center>". $value["data"] ."</center></td>";
echo "<td><center>". $value["hora"] ."</center></td>";
echo "<td>". $value["npessoa"] ."</td>";
echo "<td>". $value["nmesa"] ."</td>";
echo "</tr >";
}
}
?>
and what connects to the database
<?php
// Creating a database connection
$connection = mysqli_connect("localhost", "root", "", "peixaria");
if (!$connection) {
die("Database connection failed: " . mysqli_connect_error());
}
// Selecting a database
$db_select = mysqli_select_db($connection, "peixaria");
if (!$db_select) {
die("Database selection failed: " . mysqli_connect_error());
}
?>
the error would be on that line
$p_sql = mysql::getInstance()->prepare($Query);
It’s unusual to have a class called
mysqli
the methodgetInstance()
return what? can put it in question.– rray
I put that as a question .
– allan araujo
I don’t know that function
mysqli::getInstance
, I’m sure it’s not native to php, so it must be a class you picked up somewhere or you invented, anyway you call itmysqli
, but the expected Exception isPDOException
, as far as I know Mysqli is not a database is a php API (extension) to access the mysql database.– Guilherme Nascimento
@Guilhermenascimento actually is $p_sql = mysql::getInstance()->prepare($Query);
– allan araujo
@allanaraujo still yes this does not exist natively in PHP, and therefore without the code there is no way to know in fact what happened.
– Guilherme Nascimento
@Guilhermenascimento already put the code . just wanted to generate the report .
– allan araujo
Unfortunately I still can’t see where this code comes from
mysql::getInstance
, what you put was the User class and a foreach, but the code where you declared the functiongetInstance
and the classmysql
are not in the question. Do they really exist? If there is no answer to your problem.– Guilherme Nascimento
By your config.php code, you’re mixing PDO with mysqli, with functions that don’t exist, meaning you’re randomly programming without understanding how they work and reading the documentation, just copying random codes and mixing things that don’t make sense, It’s not supposed to work. This is a constructive criticism, do not go about doing things without reading the doc (http://php.net) and see the examples there and understand them there.
– Guilherme Nascimento
http://php.net/manual/en/book.mysqli.php
– Antonio Alexandre