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