gpt4 book ai didi

php - OOPHP 在函数内调用函数

转载 作者:行者123 更新时间:2023-11-29 00:50:35 25 4
gpt4 key购买 nike

好的,所以我正在使用 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);

抱歉,如果代码有点困惑,但提前感谢任何正确答案或信息告诉我的大脑为什么它不能完成。

最佳答案

“所以现在我正在调用一个给我特定客户的函数,但在那个调用中我想调用第二个函数来将国家首字母更改为正确的国家字符串”

为什么不在第一个函数中连接到另一个 SQL 表,获取您需要的数据而不必调用第二个函数?

关于php - OOPHP 在函数内调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8733478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com