Bruce Gust
asked on
Doing something wrong with this PDO Select Statement...
Here's my code:
I get this error: Call to a member function bindValue() on boolean in C:\wamp64\www\adm\term_cla ss_pdo.php on line 10
How can this be reading a "true" or "false" value? I'm passing "PHP" as discipline, yet I keep getting told I'm going for something else.
What am I missing?
class TermAdmin {
public function term_list($discipline) {
global $mysqli;
$sql=$mysqli->query("select * from terms where discipline=? order by discipline, term");
$sql->bindValue(1, $discipline, PDO::PARAM_STR);
$sql->execute();
$result_array = array();
while($row=$sql->fetch(PDO::FETCH_ASSOC))
{
$result_array[]=$row;
}
return $result_array;
}
}
$discipline="PHP";
$term_display=$new_list->term_list($discipline);
I get this error: Call to a member function bindValue() on boolean in C:\wamp64\www\adm\term_cla
How can this be reading a "true" or "false" value? I'm passing "PHP" as discipline, yet I keep getting told I'm going for something else.
What am I missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey, Ray!
I figured it out. I was attempting to bind a variable to my SQL without first preparing it, so this:
$sql=$mysqli->query("selec t * from terms where discipline=? order by discipline, term");
$sql->bindValue(1, $discipline, PDO::PARAM_STR);
$sql->execute();
became this...
$sql=$mysqli->prepare("sel ect * from terms where discipline=:discipline order by discipline, term");
$sql->bindValue(':discipli ne', $discipline, PDO::PARAM_STR);
$sql->execute();
...and all was well.
I am using PDO. I will call it something else besides $mysqli. I was just playing in my sandbox, but this is what I'm using:
$mysqli=new PDO('mysql:host=localhost; dbname=bgustgeneral', $user, $password);
The company I'm working for is using a different kind of convention than the global dynamic. Again, I was just knocking out thing at a time, however...
I've got another question at https://www.experts-exchange.com/questions/29003836/How-is-this-connection-happening.html. Would love to get some feedback.
I figured it out. I was attempting to bind a variable to my SQL without first preparing it, so this:
$sql=$mysqli->query("selec
$sql->bindValue(1, $discipline, PDO::PARAM_STR);
$sql->execute();
became this...
$sql=$mysqli->prepare("sel
$sql->bindValue(':discipli
$sql->execute();
...and all was well.
I am using PDO. I will call it something else besides $mysqli. I was just playing in my sandbox, but this is what I'm using:
$mysqli=new PDO('mysql:host=localhost;
The company I'm working for is using a different kind of convention than the global dynamic. Again, I was just knocking out thing at a time, however...
I've got another question at https://www.experts-exchange.com/questions/29003836/How-is-this-connection-happening.html. Would love to get some feedback.
If you find that the value is FALSE, reveal the information in $mysqli->error.
Many good examples are available in this article.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html