Hi guys. i’m kind of new to PHP so if might just be something stupid but when I try to run the following script which puts the whole database in a json I get the following errors:
Warning: mysql_numrows() expects parameter 1 to be resource, null given in /home/content/01/10936601/html/getjson.php on line 23
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /home/content/01/10936601/html/getjson.php on line 28
This is the code:
<?php $db_host = "#################"; $db_username = "###########"; $db_pass = "##########"; $db_name = "#############"; @mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL"); @mysql_select_db("$db_name") or die ("No database"); $query = "SELECT * FROM test"; $results = mysql_query($query) or die(mysql_error()); $num = mysql_num_rows($result); mysql_close(); $rows = array(); while ($r = mysql_fetch_assoc($result)) { $rows[] = $r; } echo json_encode($rows); echo "connection ok"; ?>