473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

PEAR DB::getOne question

Hi

I wondered what the return value of the getOne method in the PEAR DB class
is when no row is found:

$what = $db->getOne("SELECT field FROM table WHERE 1=2");
if($what=="") echo "emptystring";
if($what==false) echo "false";
if($what==NULL) echo "null";
echo $what;

echoes "emptystringfalsenull". Is it possible that the function returns a
value that is an empty string, false and null at the same time?

If I want to check for the existence of a row, is it okay to check for
either of the three possibilities, or is there a preferred one?

$id = $db->getOne("SELECT id FROM table WHERE condition='fulfilled');

// this one?
if($id=="") do_something();
// or this one?
if($id==false) do_something();
// or that one?
if($id != NULL) do_something();

else do_something_else($id);
Thanks for every hint.

--
Markus
Jul 17 '05 #1
3 4377
Markus Ernst wrote:
Hi

I wondered what the return value of the getOne method in the PEAR DB
class is when no row is found:

$what = $db->getOne("SELECT field FROM table WHERE 1=2");
if($what=="") echo "emptystring";
if($what==false) echo "false";
if($what==NULL) echo "null";
echo $what;


Either use === in the above if statements, or simply replace them with
var_dump($what).

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #2
Berislav Lopac wrote:
Markus Ernst wrote:
Hi

I wondered what the return value of the getOne method in the PEAR DB
class is when no row is found:

$what = $db->getOne("SELECT field FROM table WHERE 1=2");
if($what=="") echo "emptystring";
if($what==false) echo "false";
if($what==NULL) echo "null";
echo $what;


Either use === in the above if statements, or simply replace them with
var_dump($what).

Berislav


Thank you - that makes a difference indeed.

--
Markus
Jul 17 '05 #3
.oO(Markus Ernst)
Berislav Lopac wrote:
Either use === in the above if statements, or simply replace them with
var_dump($what).


Thank you - that makes a difference indeed.


The reason is the automatic typecasting of PHP. All '', FALSE and NULL
evaluate to FALSE, so in your case all three if-statements are
successful.

The === operator not only compares the values, but also the types.

Micha
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Useko Netsumi | last post by:
Suppose that I have the basic db structure as follow: imgnum varchar(16) description text imagecode varchar(16) note text photographer varchar(16) date ...
1
by: Whodat | last post by:
am new to dynamic web design and am having some trouble designing a db/web form for a hockey team. I am hoping to have a form that will update the records for each player on the team. I have...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
3
by: Patrick Olurotimi Ige | last post by:
I have DropDown List ... that populates some Data..But the DropDown does a postback that retrieves some other DropDown List with Data But i want to add Data to the Dropdpwn list they have...
6
by: Me to You | last post by:
I have installed VB.net 2003 standard and the latest MSDE. I can open and use the Northwind examples and such. I want to use the "Create New SQL Server Database" option under the server explorer...
8
by: Chris | last post by:
I had a OO model worked out which involved forms populating new instances of a class and being stored in an ArrayList. I'm now moving this over to a DB backend rather than a file - I've been...
11
by: hedbonker | last post by:
I am used to using old school ADO where I might create things like: objConn.Open( sConnectString); objRecordSet.Open ("Select * from users where UID=' + sUserID + "'", objConn); Then I have...
2
by: Spondishy | last post by:
Hi, I've taken over a publishing application that stores images in a sql server db. The architecture is basically many load balanced web servers connecting to the db. When an image is pulled...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.