gpt4 book ai didi

PHP: fatal error :调用未定义的方法 mysqli

转载 作者:行者123 更新时间:2023-11-29 08:06:56 25 4
gpt4 key购买 nike

好的,我上周问了一个问题。我得到了一些答案,其中一些没有帮助;然而,我决定重新检查我的所有连接。在我必须检查此处以使其正常运行之后,这确实解决了一些问题。接下来是由于某种原因我没有检查我的查询以确保它在 mysql 中工作。我还注意到我的版本有一种将查询输出到 PHP 代码中的方法,我就是这么做的。现在我被错误代码困住了:

Fatal error: Call to undefined method mysqli::SELECT tblConference.colConferenceName, tblSchool.colSchoolName, tblSchool.colClass, tblSurface.colSurfaceName, tblSurface.colSurfaceCompany, tblStadium.colStadiumName, tblStadium.colAddress, tblStadium.colCity, tblStadium.colRegion, tblStadium.colCounty, tblStadium.colCapacity FROM tblStadium, tblConference, tblSurface, tblSchool, tblStadiumSchool WHERE tblConference.colConferenceID = tblSchool.colConferenceID AND tblSurface.colSurfaceID = tblStadium.colSurfaceID AND tblStadium.colStadiumID = tblStadiumSchool.colStadiumID AND tblSchool.colSchoolID = tblStadiumSchool.colSchoolID AND tblSchool.colSchoolName LIKE \'A%\' ORDER BY tblSchool.colSchoolName() in C:\xampp\htdocs\stadium\alpha\a.php on line 24

现在这是我的新代码,我会尽力让它看起来像样,

    $mysqli = new mysqli("localhost", "root", "", "dbstadium");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error);
exit();
}
/* your sql query */

$sql = "SELECT tblConference.colConferenceName, tblSchool.colSchoolName, tblSchool.colClass, tblSurface.colSurfaceName, tblSurface.colSurfaceCompany, tblStadium.colStadiumName, tblStadium.colAddress, tblStadium.colCity, tblStadium.colRegion, tblStadium.colCounty, tblStadium.colCapacity FROM tblStadium, tblConference, tblSurface, tblSchool, tblStadiumSchool WHERE tblConference.colConferenceID = tblSchool.colConferenceID AND tblSurface.colSurfaceID = tblStadium.colSurfaceID AND tblStadium.colStadiumID = tblStadiumSchool.colStadiumID AND tblSchool.colSchoolID = tblStadiumSchool.colSchoolID AND tblSchool.colSchoolName LIKE \'A%\' ORDER BY tblSchool.colSchoolName";

/* query your db */
if ($result = $mysqli->$sql($sql)) {
/* fetch associative array */
while ($row = $sql->fetch_assoc())
{ /* display row */
echo '<p>School Name: ' . $row['colSchoolName'] . '</br>Conference: ' . $row['colConferenceName'] . '</br>Class: ' . $row['colClass'] . '</br>Stadium Name: ' . $row['colStadiumName'] . '</br>Address: ' . $row['colAddress'] . '</br>City: ' . $row['colCity'] . '</br>County: ' . $row['colCounty'] . '</br>Region: ' . $row['colRegion'] . '</br>Capacity: ' . $row['colCapacity'] . '</br>Surface Type: ' . $row['colSurfaceName'] . '</br>Surface Company: ' . $row['colSurfaceCompany'] . '</br>Year Installed: ' . $row['colSurfaceYear'] . '</p>';
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();

现在我不确定问题是什么。我一直在努力让它发挥作用。顺便说一句,只是让您知道查询和连接不应该成为问题。如果我缺少它们,请告诉我。

最佳答案

你的问题是:

if ($result = $mysqli->$sql($sql)) {

您基本上是在调用与 SQL 语句同名的方法,即 SELECT tblConference [...]。显然,这样的方法不存在。相反,尝试mysqli::query :

if ($result = $mysqli->query($sql)) {

顺便说一下,这一行有另一个错误:

while ($row = $sql->fetch_assoc())

$sql 仍然是您的 SQL 语句。您想要的是迭代 mysqli_result对象,您已将其放入变量 $result 中:

while ($row = $result->fetch_assoc())

关于PHP: fatal error :调用未定义的方法 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22534682/

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