I have a web site that accesses a database using PHP with MySQL . I am attempting to upgrade the code to use MySqli. I foolishly thought this was going to be simply an update to the code by changing lines such as $result=MySql_query($query) to $result=MySqli_query($query). WRONG! I've since done some research and found the need for more changes than what I assumed (yes I know what they say about AssUMe). I have made some simple changes but I can not get my query to give me a result. Yes I have done some research in this, but I am asking for help here to save me time.
To show you what I have tried I have copied my test code. Establishing the connect seems to be working, but that is the end of my success. In this example I am simply trying to get the number of rows in a table, but not having any luck. I'm asking what is a simple fix to this test code I am showing.
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
<title>Data Access Test</title>
<?php
$servername = "localhost";
$username = "*********";
$password = "##########";
$dbname = "xxxxxxxxxxx";
$link = mysqli_connect($servername, $username, $password, $dbname);
if ($link -> connect_errorno)
{
echo "failed to connect to database " . $link -> connect_error;
exit();
}
else
{
echo "success";
};
echo "trying query";
$query = "SELECT * FROM administrative where 1";
echo $query;
$result = mysqli_query($link, $query);
$numrows = mysqli_num_rows($result);
echo " Number of rows = ". $numrows;
?>
</head>
<body>
</body>
</html>
The result is: success; trying query;SELECT * FROM administrative where 1 Number of rows =
Thank you in advance for anyone that can help.