Am I missing something or do you really need all that code just to display data from your table now? I am wanting to learn MySqli but the more I look at it the more I steer clear of it. I know that soon mysql will be outdated, but to me it just makes things much more easy to get what your after.
That’s all you need to do the equivalent in MYSQLi too. In both cases you need a second statement to load the value into $row.
mysql example:
$sql = 'SELECT itemname FROM bar WHERE id = 42';
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
echo $row['itemname];
}
mysqli equivalent example:
$sql = 'SELECT itemname FROM bar WHERE id = 42';
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
echo $row['itemname'];
}
Almost no difference at all. It is only once you implement prepare statements in order to eliminate any possibility at all of injection that the mysqli becomes slightly more complicated and you get rid of all the escaping at the same time so that’s not much different in the amount of code either but a lot more secure.
I’m a bit surprised the message isn’t a “non-resource” error, but I’m guessing there is a problem with the line $link = new mysqli("localhost", "user", "password", "database");
* or whatever variant you’re using