好的,我正在使用OOPHP在Flash Builder和MYSQL之间进行通信,这两个函数都可以工作,但是当我调用另一个函数中的一个函数时,它抛出了一个错误
ERROR: Server error MySQL Error - 2014我在互联网上搜索,找不到任何合适的答案。
是不是因为第一个函数锁定了MYSQL数据库,所以第二个函数不能访问数据库?
我有这个问题的原因是在一个表中我有客户国家作为首字母,我已经创建了第二个表的首字母代表,即英国=英国,我这样做,因为当时我猜我认为这将是一个很好的数据库实践,如果客户表去了许多记录,以节省空间。
因此,现在我调用了一个函数,该函数为我提供了一个特定的客户端,但在该调用中,我想调用第二个函数来将国家/地区的首字母更改为正确的国家/地区字符串。
第一个函数
public function getClients($item) {
$stmt = mysqli_prepare($this->connection, "SELECT timestamp, id, fname, lname, dateofbirth, monthofbirth, yearofbirth,
town, country, sex, rate, comments from $this->tablename WHERE (id = $item)");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->timestamp, $row->ID, $row->fname, $row->lname, $row->dateofbirth, $row->monthofbirth,
$row->yearofbirth, $row->sex, $row->country, $row->town, $row->rate, $row->comments);
while (mysqli_stmt_fetch($stmt)) {
$row->fname = ucfirst(substr($row->fname,0,1));
$row->lname = ucfirst($row->lname);
$row->town = ucfirst($row->town);
$row->comments = strip_tags($row->comments);
$row->lname = (($row->fname) . " " . ($row->lname));
$row->country = $this->getCountry($row->country);
$row->yearofbirth = GetAge($row->dateofbirth. '-' .$row->monthofbirth. '-' .$row->yearofbirth);
$row->Pic_loc = "";
$row->Pic_loc= "SLAGSIMAGES/".($row->ID)."/image01.jpg";
$row->timestamp = new DateTime($row->timestamp);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->timestamp, $row->id,$row->fname,$row->lname,$row->sex,$row->country,$row->town,$row->dateofbirth,
$row->monthofbirth,$row->yearofbirth, $row->rate, $row->comments);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}这是第一个函数调用的第二个函数
public function getCountry($countrycode) {
$stmt = mysqli_prepare($this->connection, "SELECT country FROM countrycodes where CountryCodes ='$countrycode'");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->country);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->country);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
} 这是第一个函数中抛出错误$row->country = $this->getCountry($row->country);的那段代码
如果代码有点混乱,我很抱歉,但在此之前,感谢您给出正确的答案或信息来告诉我为什么不能这样做。
发布于 2012-01-05 04:43:55
“因此,现在我正在调用一个函数,该函数为我提供了一个特定的客户端,但在该调用中,我想调用第二个函数,以将国家/地区的首字母更改为正确的国家/地区字符串。”
为什么不直接连接到第一个函数中的其他SQL表,获得所需的数据,而不必调用第二个函数呢?
发布于 2012-01-05 04:39:01
http://www.php.net/manual/en/mysqli-stmt.execute.php备注:
使用mysqli_stmt_execute()时,在执行任何其他查询之前,必须使用mysqli_stmt_fetch()函数来获取数据。
与所有mysql一样,您可以一次执行一个查询。另一种解决方法是使用连接池,并执行以下操作
$link = (find_first_available_connection_from_pool) (should return locked link)
query($link..)
release($link) [unlock]https://stackoverflow.com/questions/8733478
复制相似问题