-3
In my code, in PHPSTORM returns that method fetch_all was not found.
<?php
$conn = require 'connection.php';
$result = $conn->query('SELECT * FROM users');
$users = $result->fetch_all(MYSQLI_ASSOC);
?>
As I just started, this is still the only code on the page, apart from HTML.
And this is the error that shows in the browser:
Fatal error: Uncaught Error: Call to a member function query() on integer in C:\Users\Administrador\Documents\estudosphp\crud\index.php:4
Code for the Connection.php page:
$conn = new mysqli('localhost', 'root', '', 'php_mysql');
if($conn-> connect_errno){
die('falhou a conexão ('. $conn -> connect_errno .')' . $conn->connect_error);
}
Post the code for "Connection.php", please
– Woss
I posted the code.
– zHardy
Have you tried
fetchAll()?– adventistaam
Yes, the result is the same.
– zHardy
fetchAll()is for PDO, which is not the case...– rbz
Use the
fetch_assocstraightforward– rbz
If
$connreceives therequire, but the fileconnection.phpreturns nothing, what should be$conn?– Woss
Gives a
print_r($conn)– adventistaam
Change the
$conn = require 'connection.php';
forrequire 'connection.php';orrequire_once 'connection.php';– adventistaam