I’ve searched all over for the solution, but the answers I find are for people that are making the same mistake:
[php]->fetch() or ->fetchAll()[/php]
I do not make this mistake, I use the correct format and still get the same results.
[php]
try
{
$db = db_connect(‘myDB’);
$search = strtolower($_GET[‘field’]);
//i am using GET vs POST for debug reasons
$sql = "SELECT *
FROM collection
WHERE name LIKE ? ORDER BY name ASC";
$params = array("%$search%");
$query = $db->prepare($sql);
$query->execute($params);
if($query)
{
echo'<table>';
while($link = $query->fetch(PDO::FETCH_OBJ)):
// also done fetch(PDO::FETCH_ASSOC)) as well, but it still gives a double result
echo’
’;print_r($link);echo’’;
bla bla bla…[/php]
the rest works fine…
what am I doing wrong?
obviously if i do a LIMIT 1 it works fine, but then I miss out on the rest of the restuls for a wildcard.
Which by the way, wild card seems to give a dupe for each entry. in other words they all come up twice
dbconnect.php
[php] function db_connect($database)
{
try {
$dbcfg = parse_ini_file(‘config.ini’);
$db = new PDO(MYSQL_TYPE.":host=".MYSQL_HOST.";dbname=".$database, MYSQL_USER, MYSQL_PASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
return $db;
}catch(PDOException $ex) {
echo "construct error: <br/>".$ex->getMessage();
}
}[/php]
thank you in advance for any insite