SELECT query does not work in mysqli (mysqli newbe)

This is my first Post here, so first I lie to day hello to all :slight_smile:

My Question:
I updated my System to PHP 7 recently, so my mysql scripts stopped working. To understand the changes, I created a simple test script, I checked a w3-school tutorial, to make sure I made all right. Then I executed the SELECT query in phpMyadmin to make sure it’s right and it worked. BUT … if I run my script in a browser, I do get “MYSQL-DATABASE-Connection successful”, but I do not get any output of my SELECT-Query. Print_r($result) echos: mysqli_result Object([current_field]=>0 [field_count]=>1 [lengths]=> [num_rows]=>1 [type]=>0) (I was actually awaiting something like "Resource ID #23 - so I do not know how to read this output).
The Database “Server_ip” contains 4 colums with just 1 row: sid, lan_ip, wlan_ip, public_ip
The code:

<?php $con = mysqli_connect("localhost","user","password","database"); if(mysqli_connect_errno()){ echo "Failed to connect to MYSQL ".mysqli_connect_errno(); } else{ echo "MYSQL-Database-Connection successful"; } $query = "SELECT public_ip FROM `Server_ip` WHERE sid=1"; $result = mysqli_query($con,$query); echo "

"; print_r($result); $row = mysqli_fetch_array($result,mysql_assoc); echo $row['public_ip']; mysqli_free_result($result); mysqli_close($con); ?>

Can anyone give me a hint why I do not get a result of my SELECT-Query? Thanks!

the mysqli_result object says you have 1 row, try to debug the $row variable, what does it contain?

print_r($row) did not give me anything, means $row was simply empty … but I solved the problem in the meantime! I changed (after studying a “mysqli” referenz) “$row = mysqli_fetch_array($result,mysql_assoc);” to “$row = mysqli_fetch_assoc($result);” and it worked :slight_smile: Not that I understand what’s the big difference??! Seems I have to relearn a lot about mysql … but anyway … thanx a lot for your input.

Sponsor our Newsletter | Privacy Policy | Terms of Service