热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PHP:致命错误:调用未定义的方法mysqli。-PHP:Fatalerror:Calltoundefinedmethodmysqli

OkayIaskedaquestionlastweek.Igotafewanswers,severalwhichdidnothelp;however,Idecid

Okay I asked a question last week. I got a few answers, several which did not help; however, I decided to recheck all of my connections. That did resolve some problems after I had to check here to make it function. Next was for some reason I did not check my query to make sure it worked in mysql. I also noticed that my version has a way to output the query into PHP code which I did. Now I am stuck with the error code:

我上周问了一个问题。我得到了几个答案,几个没有帮助;然而,我决定重新检查我所有的连接。这确实解决了一些问题,因为我必须在这里检查以使它具有功能。接下来是出于某种原因,我没有检查我的查询以确保它在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::选择tblConference。colConferenceName tblSchool。colSchoolName tblSchool。colClass tblSurface。colSurfaceName tblSurface。colSurfaceCompany tblStadium。colStadiumName tblStadium。colAddress tblStadium。colCity tblStadium。colRegion tblStadium。colCounty tblStadium。来自tblStadium, tblConference, tblSurface, tblSchool, tblStadiumSchool, tblConference的colCapacity。colCOnferenceID= tblSchool。colConferenceID tblSurface。colSurfaceID = tblStadium。colSurfaceID tblStadium。colStadiumID = tblStadiumSchool。colStadiumID tblSchool。colSchoolID = tblStadiumSchool。colSchoolID tblSchool。colSchoolName(类似于tblSchool.colSchoolName())在C:\xampp\htdocs\体育场\alpha\ A。php在24行

Now here is my new code, I will try to make it look halfway decently,

这是我的新代码,我会尽量让它看起来很漂亮,

    $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";

sql = "选择tblConference美元。colConferenceName tblSchool。colSchoolName tblSchool。colClass tblSurface。colSurfaceName tblSurface。colSurfaceCompany tblStadium。colStadiumName tblStadium。colAddress tblStadium。colCity tblStadium。colRegion tblStadium。colCounty tblStadium。来自tblStadium, tblConference, tblSurface, tblSchool, tblStadiumSchool, tblConference的colCapacity。colCOnferenceID= tblSchool。colConferenceID tblSurface。colSurfaceID = tblStadium。colSurfaceID tblStadium。colStadiumID = tblStadiumSchool。colStadiumID tblSchool。colSchoolID = tblStadiumSchool。colSchoolID 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 '

School Name: ' . $row['colSchoolName'] . '
Conference: ' . $row['colConferenceName'] . '
Class: ' . $row['colClass'] . '
Stadium Name: ' . $row['colStadiumName'] . '
Address: ' . $row['colAddress'] . '
City: ' . $row['colCity'] . '
County: ' . $row['colCounty'] . '
Region: ' . $row['colRegion'] . '
Capacity: ' . $row['colCapacity'] . '
Surface Type: ' . $row['colSurfaceName'] . '
Surface Company: ' . $row['colSurfaceCompany'] . '
Year Installed: ' . $row['colSurfaceYear'] . '

'; } /* free result set */ $result->free(); } /* close connection */ $mysqli->close();

Now I am not sure what the issue is. I been trying to get this to work. BTW just so you know the query and connection should not be an issue. If their is something I am missing just let me know.

现在我不知道这个问题是什么。我一直试着让它发挥作用。顺便说一下,您知道查询和连接不应该是一个问题。如果他们是我错过的东西,请告诉我。

2 个解决方案

#1


2  

There is your problem:

还有你的问题:

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

You're basically calling a method with the same name as your SQL statement, i.e. SELECT tblConference [...]. Such a method doesn't exist, obviously. Rather, try mysqli::query:

基本上,您调用的方法与SQL语句的名称相同,即SELECT tblConference[…]。显然,这种方法并不存在。相反,尝试mysqli::查询:

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

By the way, another error is in this line:

顺便说一下,另一个错误在这条线上:

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

$sql is still your SQL statement. What you want is to iterate over the mysqli_result object, which you've put into the variable $result:

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

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

#2


0  

This should do it

这个应该怎么做

$mysqli = new mysqli("localhost", "root", "", "dbstadium");
if (mysqli_connect_errno()) { // check connection
    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";
        if ($result = $mysqli->query($sql)) { // query your db
            while ($row = $result->fetch_object())// fetch object
            {  // display row    
                echo "

School Name: {$row->colSchoolName}
Conference: {$row->colConferenceName}
Class: {$row->colClass}
Stadium Name: {$row->colStadiumName}
Address: {$row->colAddress}
City: {$row->colCity}
County: {$row->colCounty}
Region: {$row->colRegion}
Capacity: {$row->colCapacity}
Surface Type: {$row->colSurfaceName}
Surface Company: {$row->colSurfaceCompany}
Year Installed: {$row->colSurfaceYear}

"; }//end while loop $result->free(); // free result set }//end if $mysqli->close(); // close connection

推荐阅读
author-avatar
1098502132_027279
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有