PHP: Fatal error: Call to undefined method mysqli

mdhof

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:

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

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

/* 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();

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.

Carsten

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:

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:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

php Fatal error: Call to undefined method TCPDF::addTTFfont() in

PHP OOP and MySQLi connection = Fatal error: Call to undefined method mysqli::arrayQuery()

PHP Fatal error: Call to undefined function imagecreatefrompng()

PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::bindShared() in ..Entrust/EntrustServiceProvider.php on line 72

PHP Fatal error: Call to undefined function mysqli_stmt_get_result()

PHP Fatal error: Call to undefined function?

Fatal Error - Call to undefined method "Customersss::throwError()"

PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\Util\Configuration::getExtensionConfiguration()

PHP Error: Fatal error: Call to undefined method

Fatal Error :: Call to undefined method in codeigniter

Fatal error: Call to undefined method DB::getInstance()

Fatal error Call to undefined method VmVendorPDF::convertHTMLColorToDec()

PHP Classes - Fatal error: Call to undefined method

Fatal error: Call to undefined method mysqli_stmt::get_result()

PHP Fatal error: Call to undefined method stdClass::save() - Yii framework

Fatal error: Call to undefined method mysqli::num_rows()

PHP: Fatal error: Call to undefined method case_controller

Fatal error: Call to undefined method DOMDocument::getElementsById()

PHP - Fatal Error: Call to undefined method - but method exist

xampp - Fatal error: Call to undefined method

Fatal error: Call to undefined method db::_results()

Fatal error: Call to undefined method PDOStatement::lastInsertId()

Fatal error: Call to undefined method MongoCollection::insertMany()?

Fatal error: Call to undefined method CI_DB_mysqli_driver::result()

Fatal error: Call to undefined method connectDB::prepare()

Fatal error: Uncaught Error: Call to undefined function mysqli_connect()

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::get_result()

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc()

Fatal error: Uncaught Error: Call to undefined method mysqli_result::mysqli_fetch_array() in