php连接mysql数据库,mysqli_free_result($result)参数错误
<?phpclassDBConnect{public$connection=false;public$result=false;privatefunctionfreeRe...
<?php
class DBConnect{
public $connection = false;
public $result=false;
private function freeResult(){
if ($this->result != false){
mysqli_free_result($this->result);
}
$this->result = false;
}
function doquery($sql){
$this->freeResult();
$this->result=mysqli_query($this->connection, $sql);
return $this->result;
}
function __construct(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mytest";
$this->connection = new mysqli($servername, $username, $password, $dbname);
if ($this->connection->connect_error) {
die("Connection failed: " . $this->connection->connect_error);
}
}
function __destruct(){
$this->freeResult();
if ($this->connection != false){
$this->connection->close();
}
}
}
$myConnection = new DBConnect();
?> 展开
class DBConnect{
public $connection = false;
public $result=false;
private function freeResult(){
if ($this->result != false){
mysqli_free_result($this->result);
}
$this->result = false;
}
function doquery($sql){
$this->freeResult();
$this->result=mysqli_query($this->connection, $sql);
return $this->result;
}
function __construct(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mytest";
$this->connection = new mysqli($servername, $username, $password, $dbname);
if ($this->connection->connect_error) {
die("Connection failed: " . $this->connection->connect_error);
}
}
function __destruct(){
$this->freeResult();
if ($this->connection != false){
$this->connection->close();
}
}
}
$myConnection = new DBConnect();
?> 展开
展开全部
这是因为mysqli_free_result中的参数谈蚂值为false 就是上面的晌侍侍sql语句执行没有结果,只需要做一宴吵个判断即可
if($result){
mysqli_free_result($result);
}
if($result){
mysqli_free_result($result);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定义和用法
mysql_free_result() 函数释放结果内存。
如果成功,则返回 true,如果失败,则返模悔回 false。
语法
mysql_free_result(data)
参数
描述
data 必需。要释放的结果标识符。该结果标识符是从 mysql_query() 返回的结果。
提示和注释
注释:mysql_free_result() 仅需要在考虑到返回很大的结果集时会占用多少内存时调用。在脚本结束后所有关联的内存都会被自动释放。旦雹正
例子
<?php
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));
// 释放内存肆掘
mysql_free_result($result);
$sql = "SELECT * from Customers";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));
mysql_close($con);
?>
mysql_free_result() 函数释放结果内存。
如果成功,则返回 true,如果失败,则返模悔回 false。
语法
mysql_free_result(data)
参数
描述
data 必需。要释放的结果标识符。该结果标识符是从 mysql_query() 返回的结果。
提示和注释
注释:mysql_free_result() 仅需要在考虑到返回很大的结果集时会占用多少内存时调用。在脚本结束后所有关联的内存都会被自动释放。旦雹正
例子
<?php
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));
// 释放内存肆掘
mysql_free_result($result);
$sql = "SELECT * from Customers";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));
mysql_close($con);
?>
追问
我的php没有执行mysql的时候result一直是false,执行了才会有值,才会执行freeresult,所以我不懂我的程序错在哪
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |