Reputation: 189
this is driving me crazy why aren't the results showing???
function runSQL($rsql) {
$connect = mysql_connect('localhost','xxx','xxx') or die ("Error: could not connect to database");
$db = mysql_select_db('xxx');
$result = mysql_query($rsql) or die ("Error in query: $query. " . mysql_error());
return $result;
mysql_close($connect);
}
$rsql = "SELECT * FROM subscriptions WHERE subscriptionID = 6 ";
runSQL($rsql);
$row = mysql_fetch_array($result);
echo $row['subscription'];
mysql_free_result($result);
Upvotes: 1
Views: 154
Reputation: 2679
If you close the connection before doing mysql_fetch_(assoc|array|etc)
on it, those functions will likely fail. The connection should not be closed until you're done interacting with the database, including reading the data.
Upvotes: 0
Reputation: 12628
You don't process your result ...
You call your function (runSQL) to execute the query and it returns the resultset, but you don't catch the resultset to work with it.
Use $result = runSQL($rsql);
instead of runSQL($rsql);
.
Also note that mysql_close($connect);
is never called in your code, it's unreachable as the return occurs first.
Upvotes: 3