php资源ID#11问题

The following function returns Resource id #11. How can I fix this with my present code?

function GET_PAGE() {
    global $page;
    if(isset($_GET)) {
        foreach($_GET as $key => $value){
            $query = "SELECT * FROM pages WHERE title = '{$key}'";
            $page = mysql_query($query);
            confirm_query($page);
            return $page;
        }
    }
}

You did not fetch any row.

mysql_query returns an resource that has to be interpreted by one of the mysql_fetch_*-functions. Depending on your preferences mysql_fetch_array and mysql_fetch_object would be most appropriate.


btw: The MySQL-extension is deprecated. Consider switching to PDO or MySQLi:

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. (http://www.php.net/manual/en/function.mysql-query.php)

Both allow you to use Prepared Statements to properly secure your database statements. Your posted example is prone to SQL injections!!!

Exploits of a mom - xkcd (http://xkcd.com/327/)