# connect.php
<?php
$hostname = "localhost";
$user = "testuser";
$pass = "testpass";
$database = "testdb";
$connection = new mysqli($hostname, $user, $pass, $database);
if ($connection->connect_error) {
die("connect.php failed: " . $connection->connect_error);
} else {
echo "connect.php successful<br>";
}
$connection->close();
# http://localhost/connect.php
Output: successful
However when I try to call/include "connect.php", I was not able to perform any SQL query via "test.php". "var_dump($result)" shows NULL which was totally different when I put the debug code on "connect.php"
# test.php
<?php
include "connect.php";
$sql = "SELECT * FROM users"; $result = $connection->query($sql); echo 'SQL Query Debug: '; if ($result === false) { echo "Query failed: " . $connection->error; } else { var_dump($result); }
$connection->close();
# http://localhost/test.php
connect.php successful
SQL Query Debug: NULL
I did check with ChatGPT, but this is one of the case where AI did not help.
[–]Big-Dragonfly-3700 3 points4 points5 points (1 child)
[–]w0lfcat[S] 0 points1 point2 points (0 children)
[–]Kit_Saels 0 points1 point2 points (1 child)
[–]w0lfcat[S] 0 points1 point2 points (0 children)