PDO MySQL and php like statement -
when execute query db:
select * `task` `date_time_from` '%0000%'
i few results, trying same pdo , can not manage results or errors. have done:
$dbchain = 'mysql:host='.$globals['dbhost'].';dbname='.$globals['dbname']; try{ $dbh = new pdo($dbchain, $globals['dbuser'], $globals['dbpassword']); $sql = "select * task" . "where date_time_from concat('%', :datefrom, '%')"; $a = '0000'; $stmt = $dbh->prepare($sql); $stmt->bindparam(':datefrom', $a); $stmt->execute(); $total = $stmt->rowcount(); echo $total; while ($row = $stmt->fetch()){ var_dump($row); } } catch (exception $e){ echo 'error'.$e->getmessage(); }
the result of $total = 0
. can tell me doing wrong?
i have tried this:
$sql = "select * task" . "where date_time_from :datefrom"; $a = "%0000%"; $stmt = $dbh->prepare($sql); $stmt->bindparam(':datefrom', $a); $stmt->execute();
same result $total
.
bindparam escapes "%" in query. not work expect...
you can, however, use bindvalue so...
$sql = "select * task date_time_from ?"; $stmt = $dbh->prepare($sql); $stmt->bindvalue( 1, "%0000%" ); $stmt->execute();
alternatively, if want 0 values datetime column, can this:
$sql = "select * task date_time_from = '0000-00-00'";
Comments
Post a Comment