Matthias Hanft
unread,Jul 6, 2021, 12:03:34 PM7/6/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to firebi...@googlegroups.com
Hi,
since PHP 7.4 won't contain the ibase_... functions any more,
I'm converting all my database stuff to PDO.
It's not very difficult (nearly 1:1 rewriting), with one
exception: TIMESTAMPs as query parameters.
Retrieving the reocrd count within a certain TIMESTAMP period,
with ibase_..., I did the following:
--- cut here ---
public function GetCountByAccount($aKunde, $aVon, $aBis) {
$stmt='select count(*) as ANZAHL from HTTP '.
'where KUNDE=? and DATETIME>=? and DATETIME<?;';
$trans=ibase_trans(IBASE_DEFAULT, $this->IBDatabaseWddx);
$prep=ibase_prepare($trans, $stmt);
$res=ibase_execute($prep, $aKunde, $aVon, $aBis);
if ($row=ibase_fetch_assoc($res)) // was gefunden
$myResult=intval($row['ANZAHL']);
else // nix gefunden
$myResult=0;
ibase_free_result($res);
ibase_free_query($prep);
ibase_commit($trans);
return $myResult;
} // GetCountByAccount
--- cut here ---
where $aVon and $aBis are Unix timestamps which I had constructed
by PHP's "mktime". Works well.
Now, with PDO, I guess it should read something like
--- cut here ---
public function GetCountByAccount($aKunde, $aVon, $aBis) {
$stmt='select count(*) as ANZAHL from HTTP '.
'where KUNDE=? and DATETIME>=? and DATETIME<?;';
$this->IBDatabaseWddx->beginTransaction();
$prep=$this->IBDatabaseWddx->prepare($stmt);
$res=$prep->execute(array($aKunde, $aVon, $aBis));
if ($row=$prep->fetch(PDO::FETCH_ASSOC)) // was gefunden
$myResult=intval($row['ANZAHL']);
else // nix gefunden
$myResult=0;
$prep->closeCursor();
$prep=NULL;
$this->IBDatabaseWddx->commit();
return $myResult;
} // GetCountByAccount
--- cut here ---
but no records are found.
Investigating further I found that I can *get* TIMESTAMPs from
the database by
$myPDO->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%s')); // as Unix Time - though it's a number in a string
or
$myPDO->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%Y-%m-%d %H:%M:%S')); // as string like '2021-07-06 17:56:34'
but whichever I choose, still no records are found. I have also
tried bindValue(2, $aVon, PDO::PARAM_INT) and date(...), PARAM_STR
and much more - but still no records found.
How can I use TIMESTAMP parameters in a query (preferably without
modifying the SQL query itself)?
Thanks,
-Matt