时间:2021-07-01 10:21:17 帮助过:18人阅读
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 "连接数据库失败!";
}else{
echo "连接数据库成功!";
}
$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);
?>
连接数据库成功!
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php on line 17
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php on line 18
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 "连接数据库失败!";
}else{
echo "连接数据库成功!";
}
@mysql_select_db('这里填写数据库名',$conn) or die(mysql_error()); // 加入这句
$sql = "select * from user";
function execute_data($sql, $conn){ // 加入$conn 参数
$result = mysql_query($sql);
mysql_free_result($result);
mysql_close($conn);
return $result;
}
echo execute_data($sql, $conn);
?>