trevor1940
asked on
Handling ZERO Results in a PHP PDO Query
Hi I have a PDO connection to a PostgreSQL database
How do I run a Full back query if the Preffered query has zero results
I’m doing something like this
Is this the best way to do this or is there a MYSQLi for PostgreSQL?
How do I run a Full back query if the Preffered query has zero results
I’m doing something like this
try
{
$pdo = PDO(Enter DB Connect details);
}
catch (PDOException $exec)
{
trigger_error($exec->getMessage(), E_USER_ERROR);
}
$sql = <<<SQL
select stuff from table where "MayBe" = 'I might be here' and
"always" = ?
SQL;
$sth= $pdo->prepair($sql);
$execute(array($_POST['MySearchVal'];
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
// if no results run another query before continuing
foreach($result as $row)
{
// have results Do Something
}
Is this the best way to do this or is there a MYSQLi for PostgreSQL?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Guys FYI I'll be looking at this again on Monday
In the meantime the link that ray pointed to and the docs suggest the need to do a select count(*) to accurately get the number of rows and then execute which ever query returns data.
In this context that is possibly the correct solution however in other cases do i use what Chris said or $num = $pdos->rowCount();?
PS. Apologize for the typo
In the meantime the link that ray pointed to and the docs suggest the need to do a select count(*) to accurately get the number of rows and then execute which ever query returns data.
In this context that is possibly the correct solution however in other cases do i use what Chris said or $num = $pdos->rowCount();?
PS. Apologize for the typo
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Apologies for the delay
Managed to sort the query out thanx
Managed to sort the query out thanx
Open in new window
http://php.net/manual/en/pdo.prepare.php