Warning</b> mysql_free_result (): supplied argument is not a valid MySQL result, how to fix

Source: Internet
Author: User
Tags mysql view
Warning: Mysql_free_result (): supplied argument is not a valid MySQL result
What's wrong with that?

Header (' Content-type:application/json;charset=utf8 ');
$host = ' 127.0.0.1:3307 ';
$root = ' root ';
$pwd = ' apeg1996 ';

$con = mysql_connect ($host, $root, $pwd);
if ($con = = False) {


echo "Connect database successfully!";
}

$sql = "SELECT * from user";
function Execute_data ($sql) {
$result = mysql_query ($sql);
Mysql_free_result ($result);
Mysql_close ($conn);
return $result;
}
echo Execute_data ($sql);
?>


The connection has been shown to be successful, but the error is reported.

Connect to the database successfully!

Warning: F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php



Warning: F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php


------to solve the idea----------------------
You only connected to the database system, but did not select the database to operate
mysql_select_db (' Library name ');
How else do you know that you are querying the user table in that library?

In addition, your mysql_close ($conn) is in the function, and the $conn is not passed to the function.
So there's going to be a 2nd mistake.
------to solve the idea----------------------
This post was last edited by Fdipzone on 2015-03-15 00:05:08

References:
Quote: References:

$result = mysql_query ($sql);
Switch
$result = @mysql_query ($sql) or Die (Mysql_error ());


The Web page shows the No database selected, this is not found this databases?
But I'm using the Navicat 8 for MySQL view tool.
I am here to create the database and resume the table. How should I query the tables in this database?


You don't have mysql_select_db,mysql before mysql_query. You do not know which db you need to perform the query operation.

After creating the connection, add a sentence
@mysql_select_db (' fill in the database name here', $conn) or Die (Mysql_error ());


Header (' Content-type:application/json;charset=utf8 ');
$host = ' 127.0.0.1:3307 ';
$root = ' root ';
$pwd = ' apeg1996 ';

$con = mysql_connect ($host, $root, $pwd);
if ($con = = False) {


echo "Connect database successfully!";
}

@mysql_select_db (' Fill in database name ' here, $conn) or Die (Mysql_error ()); Add this sentence

$sql = "SELECT * from user";
function Execute_data ($sql, $conn) {//join $conn parameter
$result = mysql_query ($sql);
Mysql_free_result ($result);
Mysql_close ($conn);
return $result;
}
Echo Execute_data ($sql, $conn);
?>
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.