简体   繁体   中英

Counting rows in mySQL database using PDO & PHP

I know this question has been answered before, but I actually have an error when I use an the following:

try {
    $conn = new PDO('mysql:host=localhost;dbname=open', $user, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();  
}

$count=$conn->prepare(" SELECT * FROM `dictionary` WHERE word = ':input' ");
$count->bindParam(":input",$input);
$count->execute(); 
$no=$count->rowCount();
if( $no > 0 ){
    echo "no";
}

Which gives me the error:

Fatal error: Call to a member function prepare() on a non-object in... on line 18

I don't see where the error is, particularly because I based this code off an accepted answer.

try replace this

  word = ':input'

by

  word =  :input

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM