This has had me scratching my head for a while...
my $crid = $crm->db->selectrow_array("SELECT idPerson FROM Person WHER +E email = ? OR altEmail = ?", undef, $data{'email'}, $data{'email'}); print "ERROR: " . $crm->db->errstr if $crm->db->err; print "#$data{'email'}# - $crid";
The print statements are only there for debugging. The # is around the email to check no extraneous spaces had crept in which they haven't. $crm is my CRM module and the db method returns the database handle.
The output I get is #me@example.com# - 0
idPerson is an auto increment INT which starts at 1. There is no zero in the database!
If I manually query the database I get this:
Yet my code returns 0.SELECT idPerson FROM Person WHERE email = 'me@examle.com' OR altEmail += 'me@example.com' 90 102
Things I have tried:
I have found a workaround:
But I have selectrow_array working like this in other places. I don't understand what is going on here!my $query = $crm->db->prepare("SELECT idPerson FROM Person WHERE email + = ? OR altEmail = ?"); $query->execute($data{'email'}, $data{'email'}); my $crid = $query->fetchrow_array; print "ERROR: " . $crm->db->errstr if $crm->db->err;
The DBI documentation says that selectrow_array is the equivalent of prepare, execute and fetchrow_array. It also says that selectrow_array returns undef if there is an error. Here it is returning zero which is not in the database!
Can you help me understand what is going on here?
In reply to Recalcitrant placeholders by Bod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |