简体   繁体   中英

php mysql connection does not show results why

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);

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM