php - getting an empty array when my pdo should be returning many mysql rows -
i array(0){} should returning rows;
<?php require_once('auth.php'); $conn = new pdo("mysql:host=localhost;dbname=$dbname", $username, $pw); $file = fopen('namelist1.txt','r'); $firstname = ''; $lastname = ''; $index = -1; $id = -1; $tab = ' '; try{ while ($line = fgets($file)) { $index = strrpos($line, $tab); $firstname = substr($line, 0, $index); //var_dump($firstname); $lastname = substr($line, $index + strlen($tab)); //var_dump($lastname); $stmt = $conn->prepare("select * dbname fname = :firstname , lname = :lastname"); $stmt->bindvalue(':firstname', $firstname); $stmt->bindvalue(':lastname', $lastname); $stmt->execute(); $result = $stmt->fetchall(); var_dump($result); } } catch ( exception $e ) { echo "exception @ $i"; } fclose($file); ?>
********* working sql *************
mysql> select * list fname='tara' , lname='aaba'; +----+--------------+---------------+-------+-------+-------+-----------+------------+-----------+--------+----------+-----------+-----------+-----------+-------------+-------------------+--------------------+------------+------------+----------+------------+------------+--------------+--------------+---------------------+-----------------------+-------+-------+-------+-------+----------+---------+-------------+------------------+--------------+------------+------------+ | id | statevoterid | countyvoterid | title | fname | mname | lname | namesuffix | birthdate | gender | regstnum | regstfrac | regstname | regsttype | regunittype | regstpredirection | regstpostdirection | regunitnum | regcity | regstate | regzipcode | countycode | precinctcode | precinctpart | legislativedistrict | congressionaldistrict | mail1 | mail2 | mail3 | mail4 | mailcity | mailzip | mailcountry | registrationdate | absenteetype | lastvoted | statuscode | +----+--------------+---------------+-------+-------+-------+-----------+------------+-----------+--------+----------+-----------+-----------+-----------+-------------+-------------------+--------------------+------------+------------+----------+------------+------------+--------------+--------------+---------------------+-----------------------+-------+-------+-------+-------+----------+---------+-------------+------------------+--------------+------------+------------+ | 9 | 0 | 458198 | | tara | l | aabra | | 2 | f | 5804 | | 1st | pl | | | ne | 0 | marysville | wa | 98271 | 0 | 101231 | 0 | 39 | 2 | | | | | | | | 05/05/2004 | p | 11/08/2011 | |
*********** var_dump($result) **************
array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } ....
empty array returned fetchall means there no data found.
this fact. while "working sql" working somewhere else.
so - have check input data, database, environment, typos , such.
sincerely,
Comments
Post a Comment