So I have been working on this for a number of hours now and I have looked at all the questions with similar names. I have also read the excellent guide here (https://phpdelusions.net/pdo) and the wiki here on SO (https://stackoverflow.com/tags/pdo/info), but I cannot seem to figure out the issue.
I know my connection works as I get expected results when I do not query against one specific field, LIST_105. But as soon as I try to query against LIST_105 I get no results.
Here is how I am connecting:
$options = [];
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password, $options);
$this->conn->exec("set names utf8");
I have also tried giving it these options:
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
and I have tried turning on and off emulation
$this->conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
but none of those changes have done anything.
My query is super simple:
$query = "SELECT * FROM idx_property WHERE LIST_105 = ?";
// prepare query statement
$stmt = $this->conn->prepare( $query );
$value = '22-1'; <-- I am manually adding this here for testing purposes.
$stmt->bindValue(1, $value, PDO::PARAM_STR);
// execute query
$stmt->execute();
$row = $stmt->fetch();
The query returns false every time. I have also tried using a named placeholder.
$query = "SELECT * FROM idx_property WHERE LIST_105 = :id";
...
$stmt->bindValue(':id', $value, PDO::PARAM_STR);
I have also tried using bindParam and wrapping the $value in an array and passing it directly to the execute method $stmt->execute(array($value))
and nothing works. I can just run the query directly in mysql SELECT * FROM idx_property WHERE LIST_105 = '22-1'
and I get the expected result.
I am sure I am missing something obvious, but I can't for the life of me figure out what it is.
Thanks in advance for your help.