This question already has an answer here:
I am getting this error:
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\php_programs\Query_Print_Results.php on line 18
It fails on this statement:
$result = mysqli_query($con,$query) or die(mysql_error());
I checked the value of $con
and it is Resource ID = 6
. Why? How do I get around this? Never had this happen before, but this is the first time I am not developing on localhost.
<?PHP
include 'Login_Parameters.php';
$query = "SELECT * FROM t_589";
$con = mysql_connect($DB_HOST,$DB_USER, $DB_PASS, $DB_DATABASE);
//* Check the Connection *
if (mysqli_connect_errno())
{
echo "Connect failed: " . mysqli_connect_error();
exit();
}
echo "Connected to $DB_DATABASE<br />";
$result = mysqli_query($con,$query) or die(mysql_error());
/* Get field information for all columns */
$finfo = mysqli_fetch_fields($result);
foreach ($finfo as $val) {
echo "<th>" . $val->name . "</th>";
}
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
for($i = 0; $i < mysqli_num_fields($result); $i++){
echo "<td>". $row[$i] ."</td>";
}
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
?>
</div>
Perhaps you mean to call mysqli_connect()
instead?
$con = mysqli_connect($DB_HOST,$DB_USER, $DB_PASS, $DB_DATABASE);
And as an aside, later on in your code, you need to make one other change to use mysqli_error()
.
$result = mysqli_query($con,$query) or die(mysqli_error());
You have to change this line:
$con = mysql_connect($DB_HOST,$DB_USER, $DB_PASS, $DB_DATABASE);
To this:
$con = mysqli_connect($DB_HOST,$DB_USER, $DB_PASS, $DB_DATABASE);