Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - (Fatal error: Call to a member function bind_param() on a non-object)

I get an error with this text:(sorry for my bad english I am from germany!)

Error:Fatal error: Call to a member function bind_param() on a non-object in /users/ftf/www/ccache.php on line 44

A part of the Code from ccache.php

     // Neues Datenbank-Objekt erzeugen
    $db = @new mysqli( 'localhost', 'ftf', '***', 'ftf' );
    // Pruefen ob die Datenbankverbindung hergestellt werden konnte
    if (mysqli_connect_errno() == 0)
    {
        $sql = "INSERT INTO cache
('name', 'user', 'veroefentlichung', 'beschreibung', 'FTFcode', 'STFcode', 'TTFcode', 'type', 'lat', 'lon', 'address', 'link')
VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')";
$eintrag = $db->stmt_init();
$eintrag = $db->prepare( $sql );

        $eintrag->bind_param($titel, $user, $datum, $desc, $FTF, $STF, $TTF, $type, $Lat, $Lon, $shortdesc, $genlink); // line 44

        $eintrag->execute();
        // Pruefen ob der Eintrag efolgreich war
        if ($eintrag->affected_rows == 1)
        {
            echo 'Der neue Eintrage wurde hinzugefügt.';
        }
        else
        {
            echo 'Der Eintrag konnte nicht hinzugefügt werden.';
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check your return values!

Bad: $eintrag = $db->prepare( $sql )

Good:

if( ! $eintrag = $db->prepare( $sql ) ) {
  echo 'Error: ' . $db->error;
  return false; // throw exception, die(), exit, whatever...
} else {
  // the rest of your code
}

The same goes for $eintrag->execute();.

Also, the problem is probably the fact that you're wrapping your ? placeholders in quotes. Don't do that. MySQLi does that for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...