【发布时间】:2012-01-04 20:22:33
【问题描述】:
好的,所以我使用 OOPHP 在 Flash Builder 和 MYSQL 之间进行通信,这两个函数都可以工作,但是当我在另一个函数中调用其中一个函数时,它会引发错误
错误:服务器错误 MySQL 错误 - 2014 我已经在互联网上搜索过,找不到任何合适的答案。
是不是因为第一个函数对MYSQL数据库有锁,所以第二个不能访问数据库?
我有这个问题的原因是在一个表中,我将客户国家作为首字母,我创建了第二个表,其中首字母代表什么,即 UK = United Kingdom,我当时这样做是因为我想我想如果客户端表有很多记录,这将是一个很好的数据库实践来节省空间。
所以现在我正在调用一个函数,该函数为我提供了一个特定的客户端,但在该调用中,我想调用第二个函数来将国家/地区首字母更改为正确的国家/地区字符串。
第一个函数
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);
对不起,如果代码有点混乱,但提前感谢任何正确的答案或信息,告诉我的大脑为什么不能完成。
【问题讨论】:
-
"coz" 不是一个词,请不要在您的 SO 帖子中使用聊天对话。
-
是的,这是因为您使用第一个 SQL 打开/锁定了一个连接。也许你可以
JOINSQL 进入一次查找,或者执行一次获取/关闭然后执行另一次获取。 -
谢谢 Rudu,我也是这么想的
标签: php mysql sql flash-builder