-2
I’m having a problem connecting to the Mysqli database, is making several mistakes, follow the mistakes below:
PHP Warning: mysqli_query() expects parameter 1 to be mysqli, null given in D:\web\localuser\riobonitopiscinas\www\acessorios-para-construcao.php on line 63
PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in D:\web\localuser\riobonitopiscinas\www\acessorios-para-construcao.php on line 66
PHP Warning: mysqli_close() expects parameter 1 to be mysqli, null given in D:\web\localuser\riobonitopiscinas\www\acessorios-para-construcao.php on line 84
And my page code is:
<?php
include ('admin/include/conexao.php');
$result = mysqli_query($con,"SELECT * FROM produto WHERE id_subcategoria=78");
while($row = mysqli_fetch_array($result)) {
?>
<?php include ('includes/box.php'); ?>
<?php
}
mysqli_close($con);
?>
My code of the connection :
<?php
$parseini = parse_ini_file('admin/ini/config.ini', true);
$dsn = sprintf('mysql:dbname=%s;host=%s',$parseini['bancodedados']['dbname'], $parseini['bancodedados']['host']);
try {
$conexao = new PDO($dsn, $parseini['bancodedados']['usuario'], $parseini['bancodedados']['senha']);
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());
}
?>
"I’m with a problem in making connection with the Bank", If the problem is with the connection, you need to show us the file that makes the connection. All errors cited are null object, which indicates that their variable
$con
is void.– Woss
<?php $parseini = parse_ini_file('admin/ini/config.ini', true); $dsn = sprintf('mysql:dbname=%s;host=%s',$parseini['bancodedados']['dbname'], $parseini['bancodedados']['host']); Try { $connection = new PDO($dsn, $parseini['bancodedados']['user'], $parseini['bancodedados']['password']); } catch (Pdoexception $e) { die('Connection failed: ' . $e->getMessage()); } ?>
– Vinicius
@Vinicius, put the connection code in the question itself and not here in the comments.
– Thiago Drulla
Ready this in the question
– Vinicius
You connect the bank in
$conexao
, but uses$con
? Why is that?– Woss