PHP pages won"t open correctly on my server.

PHP pages won"t open correctly on my server.

am 24.08.2009 20:30:00 von x0ml

PHP pages won't open at all on my server. HTML pages open fine, but when
going to the PHP pages that are on my server, the browser tries to download
the page like a file instead of presenting it by the browser. What can I do
to make the PHP processor to be handled properly? Do I need to recompile it
again, and if so, what switches should I use?

I am running Apache version 2.2.11. I'm on Fedora 2.6.11-1.1369_FC4 on that
particular server. I'm running PHP 5.2.9 which I downloaded directly from
the php web site, then untarred, ran make, and make install commands as
described in the php INSTALL file that was included with the distribution..

==================

Example 2-4. Installation Instructions (Apache 2 Shared Module Version)
1. gzip -d httpd-2_0_NN.tar.gz
2. tar xvf httpd-2_0_NN.tar
3. gunzip php-NN.tar.gz
4. tar -xvf php-NN.tar
5. cd httpd-2_0_NN
6. ./configure --enable-so
7. make
8. make install

==================

You will probably try to talk me into using yum, I would like to but it is
broken and fixing it leads to even more troblemshooting. I want to fix this
first, then I will tackle the yum issue next.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP pages won"t open correctly on my server.

am 24.08.2009 21:27:49 von Ryan Cavicchioni

On Mon, Aug 24, 2009 at 01:30:00PM -0500, RRT wrote:
> PHP pages won't open at all on my server. HTML pages open fine, but when
> going to the PHP pages that are on my server, the browser tries to download
> the page like a file instead of presenting it by the browser. What can I do
> to make the PHP processor to be handled properly? Do I need to recompile it
> again, and if so, what switches should I use?
>
> I am running Apache version 2.2.11. I'm on Fedora 2.6.11-1.1369_FC4 on that
> particular server. I'm running PHP 5.2.9 which I downloaded directly from
> the php web site, then untarred, ran make, and make install commands as
> described in the php INSTALL file that was included with the distribution..

Hello,

If PHP is installed properly, look at step 14 (loading the module in
apache) and step 15 (Tell Apache to parse certain extensions as PHP)
in the PHP installation documentation.

http://www.php.net/manual/en/install.unix.apache2.php

Regards,

-- Ryan Cavicchioni

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP pages won"t open correctly on my server.

am 24.08.2009 23:51:46 von x0ml

That link won't load for me. Did you get it to load OK for you?


"Ryan Cavicchioni" wrote in message
news:20090824192749.GA13758@mail.confabulator.net...
> On Mon, Aug 24, 2009 at 01:30:00PM -0500, RRT wrote:
>> PHP pages won't open at all on my server. HTML pages open fine, but when
>> going to the PHP pages that are on my server, the browser tries to
>> download
>> the page like a file instead of presenting it by the browser. What can I
>> do
>> to make the PHP processor to be handled properly? Do I need to recompile
>> it
>> again, and if so, what switches should I use?
>>
>> I am running Apache version 2.2.11. I'm on Fedora 2.6.11-1.1369_FC4 on
>> that
>> particular server. I'm running PHP 5.2.9 which I downloaded directly
>> from
>> the php web site, then untarred, ran make, and make install commands as
>> described in the php INSTALL file that was included with the
>> distribution..
>
> Hello,
>
> If PHP is installed properly, look at step 14 (loading the module in
> apache) and step 15 (Tell Apache to parse certain extensions as PHP)
> in the PHP installation documentation.
>
> http://www.php.net/manual/en/install.unix.apache2.php
>
> Regards,
>
> -- Ryan Cavicchioni



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

How to output a NULL field?

am 25.08.2009 20:00:04 von David Stoltz

$rs->Fields(22) equals a NULL in the database

My Code:

if(empty($rs->Fields(22))){
$q4 =3D "";
}else{
$q4 =3D $rs->Fields(22);
}

Produces this error:
Fatal error: Can't use method return value in write context in
D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32

Line 32 is the "if" line...

If I switch the code to (using is_null):
if(is_null($rs->Fields(22))){
$q4 =3D "";
}else{
$q4 =3D $rs->Fields(22);
}

It produces this error:
Catchable fatal error: Object of class variant could not be converted to
string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196

Line 196 is:

What am I doing wrong?

Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 25.08.2009 20:17:04 von Phpster

On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz wrote:
> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> =A0 =A0 =A0 =A0$q4 =3D "";
> }else{
> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> =A0 =A0 =A0 =A0$q4 =3D "";
> }else{
> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is:
>
> What am I doing wrong?
>
> Thanks!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


$q4 =3D '' . $rs->Fields(22);

Note that it's two single quotes
--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 25.08.2009 20:47:58 von David Stoltz

if(empty($rs->Fields(22))){
$q4 =3D '';
}else{
$q4 =3D ''.$rs->Fields(22);
} =20

Still produces errors, whether using "empty" or "is_null"....with single =
quotes....

???

-----Original Message-----
From: Bastien Koert [mailto:phpster@gmail.com]=20
Sent: Tuesday, August 25, 2009 2:17 PM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz wrote:
> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> =A0 =A0 =A0 =A0$q4 =3D "";
> }else{
> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> =A0 =A0 =A0 =A0$q4 =3D "";
> }else{
> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted =
to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is:
>
> What am I doing wrong?
>
> Thanks!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


$q4 =3D '' . $rs->Fields(22);

Note that it's two single quotes
--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 25.08.2009 21:00:33 von Lars Torben Wilson

2009/8/25 David Stoltz :
> if(empty($rs->Fields(22))){

Hi David,

You cannot call empty() on a function or class method like that. From
the manual:

Note: empty() only checks variables as anything else will result in
a parse error. In other words, the following will not work:
empty(trim($name)). - http://www.php.net/empty

You should assign the result of $rs->Fields(22) to a variable before
calling empty() on it, or use a class variable access to check it, or
check it first within the class and have Fields() return a suitable
value if needed.


Regards,

Torben

> =A0 =A0 =A0 =A0$q4 =3D '';
> }else{
> =A0 =A0 =A0 =A0$q4 =3D ''.$rs->Fields(22);
> }
>
> Still produces errors, whether using "empty" or "is_null"....with single =
quotes....
>
> ???
>
> -----Original Message-----
> From: Bastien Koert [mailto:phpster@gmail.com]
> Sent: Tuesday, August 25, 2009 2:17 PM
> To: David Stoltz
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz wrote:
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>> =A0 =A0 =A0 =A0$q4 =3D "";
>> }else{
>> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>> =A0 =A0 =A0 =A0$q4 =3D "";
>> }else{
>> =A0 =A0 =A0 =A0$q4 =3D $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is:
>>
>> What am I doing wrong?
>>
>> Thanks!
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> $q4 =3D =A0'' . $rs->Fields(22);
>
> Note that it's two single quotes
> --
>
> Bastien
>
> Cat, the other other white meat
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 25.08.2009 21:22:54 von Shawn McKenzie

David Stoltz wrote:
> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is:
>
> What am I doing wrong?
>
> Thanks!

First off, if the value is NULL in the database then in PHP it will be
the string "NULL" and not a null value as far as I remember. Second,
you cant use a function/method in empty(). Thirdly, the string "NULL"
is not empty. I'm not sure what DB class you're using here or what the
Fields() method actually returns. You should do a
var_dump($rs->Fields(22)) to see. If it returns a string (especially
"NULL"), then this or some variation should work:

$q4 = $rs->Fields(22);

if($q4 == "NULL"){
$q4 = "";
}

If it returns an empty string or false then you may have nothing to do.

--
Thanks!
-Shawn
http://www.spidean.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 25.08.2009 22:02:25 von Shawn McKenzie

Shawn McKenzie wrote:
> First off, if the value is NULL in the database then in PHP it will be
> the string "NULL" and not a null value as far as I remember. Second,
> you cant use a function/method in empty(). Thirdly, the string "NULL"
> is not empty. I'm not sure what DB class you're using here or what the
> Fields() method actually returns. You should do a
> var_dump($rs->Fields(22)) to see. If it returns a string (especially
> "NULL"), then this or some variation should work:
>
> $q4 = $rs->Fields(22);
>
> if($q4 == "NULL"){
> $q4 = "";
> }
>
> If it returns an empty string or false then you may have nothing to do.
>
DOH! My bad. MySQL stores an empty value based upon the field type for
NULL. So if the field type is int then it sets it to 0 and if its
varchar, etc, it sets it to an empty string "". The MySQL functions
seem to return everything as a string, so for an int field it returns
the string "0", so:

$q4 = $rs->Fields(22);

if(empty($q4)){
$q4 = "";
}

But I'm not sure what benefit you get from this except that "0" is
changed to "".

--
Thanks!
-Shawn
http://www.spidean.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 25.08.2009 22:38:57 von Paul M Foster

On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:

> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is:
>
> What am I doing wrong?
>
> Thanks!

Just a thought... do you really mean $rs->Fields(22) or do you mean
$rs->Fields[22]? The former is a function call and the latter is an
array variable.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 13:29:53 von David Stoltz

Paul,

This all started because when I try this:

Fields(22);?>

It work fine, as long as there is a non-null value there, otherwise it
produces an error.

Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
sure if that matters....

But "echo $rs->Fields(22)" works perfectly for dumping values out of my
$rs recordset...that is, unless the value is NULL is the database - then
I get:

Catchable fatal error: Object of class variant could not be converted to
string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176


-----Original Message-----
From: Paul M Foster [mailto:paulf@quillandmouse.com]=20
Sent: Tuesday, August 25, 2009 4:39 PM
To: php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:

> $rs->Fields(22) equals a NULL in the database
>=20
> My Code:
>=20
> if(empty($rs->Fields(22))){
> $q4 =3D "";
> }else{
> $q4 =3D $rs->Fields(22);
> }
>=20
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>=20
> Line 32 is the "if" line...
>=20
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> $q4 =3D "";
> }else{
> $q4 =3D $rs->Fields(22);
> }
>=20
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted
to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>=20
> Line 196 is:
>=20
> What am I doing wrong?
>=20
> Thanks!

Just a thought... do you really mean $rs->Fields(22) or do you mean
$rs->Fields[22]? The former is a function call and the latter is an
array variable.

Paul

--=20
Paul M. Foster

--=20
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 13:39:17 von hack988 hack988

use is_null() check it

2009/8/26 David Stoltz :
> Paul,
>
> This all started because when I try this:
>
> Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> $rs recordset...that is, unless the value is NULL is the database - then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>> =A0 =A0 =A0 $q4 =3D "";
>> }else{
>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>> =A0 =A0 =A0 $q4 =3D "";
>> }else{
>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted
> to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is:
>>
>> What am I doing wrong?
>>
>> Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 13:51:26 von David Stoltz

I tried that -it's in the first part of my message


-----Original Message-----
From: hack988 hack988 [mailto:hack988@dev.htwap.com]=20
Sent: Wednesday, August 26, 2009 7:39 AM
To: David Stoltz
Cc: Paul M Foster; php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

use is_null() check it

2009/8/26 David Stoltz :
> Paul,
>
> This all started because when I try this:
>
> Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of =
my
> $rs recordset...that is, unless the value is NULL is the database - =
then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted =
to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>> =A0 =A0 =A0 $q4 =3D "";
>> }else{
>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>> =A0 =A0 =A0 $q4 =3D "";
>> }else{
>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted
> to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is:
>>
>> What am I doing wrong?
>>
>> Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 14:07:40 von hack988 hack988

Could you post your database's class to here?
I'm use mssql with php for several years and read NULL Fields is never
appear your case.

2009/8/26 David Stoltz :
> I tried that -it's in the first part of my message
>
>
> -----Original Message-----
> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> Sent: Wednesday, August 26, 2009 7:39 AM
> To: David Stoltz
> Cc: Paul M Foster; php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> use is_null() check it
>
> 2009/8/26 David Stoltz :
>> Paul,
>>
>> This all started because when I try this:
>>
>> Fields(22);?>
>>
>> It work fine, as long as there is a non-null value there, otherwise it
>> produces an error.
>>
>> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
>> sure if that matters....
>>
>> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
>> $rs recordset...that is, unless the value is NULL is the database - then
>> I get:
>>
>> Catchable fatal error: Object of class variant could not be converted to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>>
>>
>> -----Original Message-----
>> From: Paul M Foster [mailto:paulf@quillandmouse.com]
>> Sent: Tuesday, August 25, 2009 4:39 PM
>> To: php-general@lists.php.net
>> Subject: Re: [PHP] How to output a NULL field?
>>
>> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>>
>>> $rs->Fields(22) equals a NULL in the database
>>>
>>> My Code:
>>>
>>> if(empty($rs->Fields(22))){
>>> =A0 =A0 =A0 $q4 =3D "";
>>> }else{
>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>> }
>>>
>>> Produces this error:
>>> Fatal error: Can't use method return value in write context in
>>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>>
>>> Line 32 is the "if" line...
>>>
>>> If I switch the code to (using is_null):
>>> if(is_null($rs->Fields(22))){
>>> =A0 =A0 =A0 $q4 =3D "";
>>> }else{
>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>> }
>>>
>>> It produces this error:
>>> Catchable fatal error: Object of class variant could not be converted
>> to
>>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>>
>>> Line 196 is:
>>>
>>> What am I doing wrong?
>>>
>>> Thanks!
>>
>> Just a thought... do you really mean $rs->Fields(22) or do you mean
>> $rs->Fields[22]? The former is a function call and the latter is an
>> array variable.
>>
>> Paul
>>
>> --
>> Paul M. Foster
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 14:29:11 von Trevor Gryffyn

Sorry, didn't follow this whole thread but have you tried print_r() or
var_dump() to see what it looks like when it's type "variant"? I'd be
curious to see what you'd find in it.

Also, I forget about SQL Server, but MySQL has a function ifnull() which
can make sure you never return a null value. This is also handy for
checking for empty fields where you don't know if it's going to be an
empty string or a null:

SELECT * FROM table WHERE ifnull(somefield, '') = ''

If you know which columns are nullable, try seeing if there's an ifnull()
function in SQL Server to adjust the data before it even gets to your DB
class.

-TG

----- Original Message -----
From: "David Stoltz"
To: "Paul M Foster" ,
Date: Wed, 26 Aug 2009 07:29:53 -0400
Subject: RE: [PHP] How to output a NULL field?

> Paul,
>
> This all started because when I try this:
>
> Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> $rs recordset...that is, unless the value is NULL is the database - then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
> > $rs->Fields(22) equals a NULL in the database
> >
> > My Code:
> >
> > if(empty($rs->Fields(22))){
> > $q4 = "";
> > }else{
> > $q4 = $rs->Fields(22);
> > }
> >
> > Produces this error:
> > Fatal error: Can't use method return value in write context in
> > D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
> >
> > Line 32 is the "if" line...
> >
> > If I switch the code to (using is_null):
> > if(is_null($rs->Fields(22))){
> > $q4 = "";
> > }else{
> > $q4 = $rs->Fields(22);
> > }
> >
> > It produces this error:
> > Catchable fatal error: Object of class variant could not be converted
> to
> > string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
> >
> > Line 196 is:
> >
> > What am I doing wrong?
> >
> > Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 14:46:45 von Stut

2009/8/26 David Stoltz :
> Paul,
>
> This all started because when I try this:
>
> Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> $rs recordset...that is, unless the value is NULL is the database - then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176

That error indicates that you're not getting NULL since NULL is easily
converted to a string.

Try this...

$var =3D $rs->Fields(22);
var_dump($var);

....and tell us what you get.

-Stuart

--=20
http://stut.net/

> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>>       $q4 =3D "";
>> }else{
>>       $q4 =3D $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>>       $q4 =3D "";
>> }else{
>>       $q4 =3D $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted
> to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is:
>>
>> What am I doing wrong?
>>
>> Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 15:47:17 von David Stoltz

VGhpczoNCiR2YXIgPSAkcnMtPkZpZWxkcygyMik7DQp2YXJfZHVtcCgkdmFy KTsNCg0KUHJvZHVj
ZXMgdGhpczoNCm9iamVjdCh2YXJpYW50KSMzICgwKSB7IH0NCg0KLS0tLS1P cmlnaW5hbCBNZXNz
YWdlLS0tLS0NCkZyb206IFN0dWFydCBbbWFpbHRvOnN0dXR0bGVAZ21haWwu Y29tXSANClNlbnQ6
IFdlZG5lc2RheSwgQXVndXN0IDI2LCAyMDA5IDg6NDcgQU0NClRvOiBEYXZp ZCBTdG9sdHoNCkNj
OiBQYXVsIE0gRm9zdGVyOyBwaHAtZ2VuZXJhbEBsaXN0cy5waHAubmV0DQpT dWJqZWN0OiBSZTog
W1BIUF0gSG93IHRvIG91dHB1dCBhIE5VTEwgZmllbGQ/DQoNCjIwMDkvOC8y NiBEYXZpZCBTdG9s
dHogPERzdG9sdHpAc2hoLm9yZz46DQo+IFBhdWwsDQo+DQo+IFRoaXMgYWxs IHN0YXJ0ZWQgYmVj
YXVzZSB3aGVuIEkgdHJ5IHRoaXM6DQo+DQo+IDw/cGhwIGVjaG8gJHJzLT5G aWVsZHMoMjIpOz8+
DQo+DQo+IEl0IHdvcmsgZmluZSwgYXMgbG9uZyBhcyB0aGVyZSBpcyBhIG5v bi1udWxsIHZhbHVl
IHRoZXJlLCBvdGhlcndpc2UgaXQNCj4gcHJvZHVjZXMgYW4gZXJyb3IuDQo+ DQo+IEFsc28sIEkn
bSB3b3JraW5nIHdpdGggYSBNaWNyb3NvZnQgU1FMIDIwMDAgZGF0YWJhc2Us IG5vdCBNeVNRTC4u
Li5ub3QNCj4gc3VyZSBpZiB0aGF0IG1hdHRlcnMuLi4uDQo+DQo+IEJ1dCAi ZWNobyAkcnMtPkZp
ZWxkcygyMikiIHdvcmtzIHBlcmZlY3RseSBmb3IgZHVtcGluZyB2YWx1ZXMg b3V0IG9mIG15DQo+
ICRycyByZWNvcmRzZXQuLi50aGF0IGlzLCB1bmxlc3MgdGhlIHZhbHVlIGlz IE5VTEwgaXMgdGhl
IGRhdGFiYXNlIC0gdGhlbg0KPiBJIGdldDoNCj4NCj4gQ2F0Y2hhYmxlIGZh dGFsIGVycm9yOiBP
YmplY3Qgb2YgY2xhc3MgdmFyaWFudCBjb3VsZCBub3QgYmUgY29udmVydGVk IHRvDQo+IHN0cmlu
ZyBpbiBEOlxJbmV0cHViXHd3d3Jvb3RcZXZhbHVhdGlvbnNcbG9va3VwMi5w aHAgb24gbGluZSAx
NzYNCg0KVGhhdCBlcnJvciBpbmRpY2F0ZXMgdGhhdCB5b3UncmUgbm90IGdl dHRpbmcgTlVMTCBz
aW5jZSBOVUxMIGlzIGVhc2lseQ0KY29udmVydGVkIHRvIGEgc3RyaW5nLg0K DQpUcnkgdGhpcy4u
Lg0KDQokdmFyID0gJHJzLT5GaWVsZHMoMjIpOw0KdmFyX2R1bXAoJHZhcik7 DQoNCi4uLmFuZCB0
ZWxsIHVzIHdoYXQgeW91IGdldC4NCg0KLVN0dWFydA0KDQotLSANCmh0dHA6 Ly9zdHV0Lm5ldC8N
Cg0KPiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBQYXVs IE0gRm9zdGVyIFtt
YWlsdG86cGF1bGZAcXVpbGxhbmRtb3VzZS5jb21dDQo+IFNlbnQ6IFR1ZXNk YXksIEF1Z3VzdCAy
NSwgMjAwOSA0OjM5IFBNDQo+IFRvOiBwaHAtZ2VuZXJhbEBsaXN0cy5waHAu bmV0DQo+IFN1Ympl
Y3Q6IFJlOiBbUEhQXSBIb3cgdG8gb3V0cHV0IGEgTlVMTCBmaWVsZD8NCj4N Cj4gT24gVHVlLCBB
dWcgMjUsIDIwMDkgYXQgMDI6MDA6MDRQTSAtMDQwMCwgRGF2aWQgU3RvbHR6 IHdyb3RlOg0KPg0K
Pj4gJHJzLT5GaWVsZHMoMjIpIGVxdWFscyBhIE5VTEwgaW4gdGhlIGRhdGFi YXNlDQo+Pg0KPj4g
TXkgQ29kZToNCj4+DQo+PiBpZihlbXB0eSgkcnMtPkZpZWxkcygyMikpKXsN Cj4+IMKgIMKgIMKg
ICRxNCA9ICIiOw0KPj4gfWVsc2V7DQo+PiDCoCDCoCDCoCAkcTQgPSAkcnMt PkZpZWxkcygyMik7
DQo+PiB9DQo+Pg0KPj4gUHJvZHVjZXMgdGhpcyBlcnJvcjoNCj4+IEZhdGFs IGVycm9yOiBDYW4n
dCB1c2UgbWV0aG9kIHJldHVybiB2YWx1ZSBpbiB3cml0ZSBjb250ZXh0IGlu DQo+PiBEOlxJbmV0
cHViXHd3d3Jvb3RcZXZhbHVhdGlvbnNcbG9va3VwMi5waHAgb24gbGluZSAz Mg0KPj4NCj4+IExp
bmUgMzIgaXMgdGhlICJpZiIgbGluZS4uLg0KPj4NCj4+IElmIEkgc3dpdGNo IHRoZSBjb2RlIHRv
ICh1c2luZyBpc19udWxsKToNCj4+IGlmKGlzX251bGwoJHJzLT5GaWVsZHMo MjIpKSl7DQo+PiDC
oCDCoCDCoCAkcTQgPSAiIjsNCj4+IH1lbHNlew0KPj4gwqAgwqAgwqAgJHE0 ID0gJHJzLT5GaWVs
ZHMoMjIpOw0KPj4gfQ0KPj4NCj4+IEl0IHByb2R1Y2VzIHRoaXMgZXJyb3I6 DQo+PiBDYXRjaGFi
bGUgZmF0YWwgZXJyb3I6IE9iamVjdCBvZiBjbGFzcyB2YXJpYW50IGNvdWxk IG5vdCBiZSBjb252
ZXJ0ZWQNCj4gdG8NCj4+IHN0cmluZyBpbiBEOlxJbmV0cHViXHd3d3Jvb3Rc ZXZhbHVhdGlvbnNc
bG9va3VwMi5waHAgb24gbGluZSAxOTYNCj4+DQo+PiBMaW5lIDE5NiBpczog PD9waHAgZWNobyAk
cTQ7Pz4NCj4+DQo+PiBXaGF0IGFtIEkgZG9pbmcgd3Jvbmc/DQo+Pg0KPj4g VGhhbmtzIQ0KPg0K
PiBKdXN0IGEgdGhvdWdodC4uLiBkbyB5b3UgcmVhbGx5IG1lYW4gJHJzLT5G aWVsZHMoMjIpIG9y
IGRvIHlvdSBtZWFuDQo+ICRycy0+RmllbGRzWzIyXT8gVGhlIGZvcm1lciBp cyBhIGZ1bmN0aW9u
IGNhbGwgYW5kIHRoZSBsYXR0ZXIgaXMgYW4NCj4gYXJyYXkgdmFyaWFibGUu DQo+DQo+IFBhdWwN
Cj4NCj4gLS0NCj4gUGF1bCBNLiBGb3N0ZXINCj4NCj4gLS0NCj4gUEhQIEdl bmVyYWwgTWFpbGlu
ZyBMaXN0IChodHRwOi8vd3d3LnBocC5uZXQvKQ0KPiBUbyB1bnN1YnNjcmli ZSwgdmlzaXQ6IGh0
dHA6Ly93d3cucGhwLm5ldC91bnN1Yi5waHANCj4NCj4NCj4gLS0NCj4gUEhQ IEdlbmVyYWwgTWFp
bGluZyBMaXN0IChodHRwOi8vd3d3LnBocC5uZXQvKQ0KPiBUbyB1bnN1YnNj cmliZSwgdmlzaXQ6
IGh0dHA6Ly93d3cucGhwLm5ldC91bnN1Yi5waHANCj4NCj4NCg==

RE: How to output a NULL field?

am 26.08.2009 15:51:33 von David Stoltz

Sorry - I don't know what you mean by DB class?

I'm using Microsoft SQL 2000....with this code:

//create an instance of the ADO connection object
$conn =3D new COM ("ADODB.Connection")
or die("Cannot start ADO");
//define connection string, specify database driver
$connStr =3D =
"PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DATA BASE=3Dxxxx";=
=20
$conn->open($connStr); //Open the connection to the database

$query =3D "SELECT * FROM eval_evaluations WHERE id =3D =
".$_POST["eval"];

$rs =3D $conn->execute($query);

echo $rs->Fields(22); //this is where that particular field is NULL, and =
produces the error

.....

-----Original Message-----
From: hack988 hack988 [mailto:hack988@dev.htwap.com]=20
Sent: Wednesday, August 26, 2009 8:08 AM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

Could you post your database's class to here?
I'm use mssql with php for several years and read NULL Fields is never
appear your case.

2009/8/26 David Stoltz :
> I tried that -it's in the first part of my message
>
>
> -----Original Message-----
> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> Sent: Wednesday, August 26, 2009 7:39 AM
> To: David Stoltz
> Cc: Paul M Foster; php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> use is_null() check it
>
> 2009/8/26 David Stoltz :
>> Paul,
>>
>> This all started because when I try this:
>>
>> Fields(22);?>
>>
>> It work fine, as long as there is a non-null value there, otherwise =
it
>> produces an error.
>>
>> Also, I'm working with a Microsoft SQL 2000 database, not =
MySQL....not
>> sure if that matters....
>>
>> But "echo $rs->Fields(22)" works perfectly for dumping values out of =
my
>> $rs recordset...that is, unless the value is NULL is the database - =
then
>> I get:
>>
>> Catchable fatal error: Object of class variant could not be converted =
to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>>
>>
>> -----Original Message-----
>> From: Paul M Foster [mailto:paulf@quillandmouse.com]
>> Sent: Tuesday, August 25, 2009 4:39 PM
>> To: php-general@lists.php.net
>> Subject: Re: [PHP] How to output a NULL field?
>>
>> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>>
>>> $rs->Fields(22) equals a NULL in the database
>>>
>>> My Code:
>>>
>>> if(empty($rs->Fields(22))){
>>> =A0 =A0 =A0 $q4 =3D "";
>>> }else{
>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>> }
>>>
>>> Produces this error:
>>> Fatal error: Can't use method return value in write context in
>>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>>
>>> Line 32 is the "if" line...
>>>
>>> If I switch the code to (using is_null):
>>> if(is_null($rs->Fields(22))){
>>> =A0 =A0 =A0 $q4 =3D "";
>>> }else{
>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>> }
>>>
>>> It produces this error:
>>> Catchable fatal error: Object of class variant could not be =
converted
>> to
>>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>>
>>> Line 196 is:
>>>
>>> What am I doing wrong?
>>>
>>> Thanks!
>>
>> Just a thought... do you really mean $rs->Fields(22) or do you mean
>> $rs->Fields[22]? The former is a function call and the latter is an
>> array variable.
>>
>> Paul
>>
>> --
>> Paul M. Foster
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 16:00:41 von hack988 hack988

my god you use ado connect sorry I'm use php_mysql extentions for all
mssql function.
I'm never use ado connect before.

2009/8/26 David Stoltz :
> Sorry - I don't know what you mean by DB class?
>
> I'm using Microsoft SQL 2000....with this code:
>
> > //create an instance of the =A0ADO connection object
> $conn =3D new COM ("ADODB.Connection")
> =A0or die("Cannot start ADO");
> //define connection string, specify database driver
> $connStr =3D "PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DATA =
BASE=3Dxxxx";
> $conn->open($connStr); //Open the connection to the database
>
> $query =3D "SELECT * FROM eval_evaluations WHERE id =3D ".$_POST["eval"];
>
> $rs =3D $conn->execute($query);
>
> echo $rs->Fields(22); //this is where that particular field is NULL, and =
produces the error
>
> ....
>
> -----Original Message-----
> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> Sent: Wednesday, August 26, 2009 8:08 AM
> To: David Stoltz
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> Could you post your database's class to here?
> I'm use mssql with php for several years and read NULL Fields is never
> appear your case.
>
> 2009/8/26 David Stoltz :
>> I tried that -it's in the first part of my message
>>
>>
>> -----Original Message-----
>> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
>> Sent: Wednesday, August 26, 2009 7:39 AM
>> To: David Stoltz
>> Cc: Paul M Foster; php-general@lists.php.net
>> Subject: Re: [PHP] How to output a NULL field?
>>
>> use is_null() check it
>>
>> 2009/8/26 David Stoltz :
>>> Paul,
>>>
>>> This all started because when I try this:
>>>
>>> Fields(22);?>
>>>
>>> It work fine, as long as there is a non-null value there, otherwise it
>>> produces an error.
>>>
>>> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
>>> sure if that matters....
>>>
>>> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
>>> $rs recordset...that is, unless the value is NULL is the database - the=
n
>>> I get:
>>>
>>> Catchable fatal error: Object of class variant could not be converted t=
o
>>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>>>
>>>
>>> -----Original Message-----
>>> From: Paul M Foster [mailto:paulf@quillandmouse.com]
>>> Sent: Tuesday, August 25, 2009 4:39 PM
>>> To: php-general@lists.php.net
>>> Subject: Re: [PHP] How to output a NULL field?
>>>
>>> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>>>
>>>> $rs->Fields(22) equals a NULL in the database
>>>>
>>>> My Code:
>>>>
>>>> if(empty($rs->Fields(22))){
>>>> =A0 =A0 =A0 $q4 =3D "";
>>>> }else{
>>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>>> }
>>>>
>>>> Produces this error:
>>>> Fatal error: Can't use method return value in write context in
>>>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>>>
>>>> Line 32 is the "if" line...
>>>>
>>>> If I switch the code to (using is_null):
>>>> if(is_null($rs->Fields(22))){
>>>> =A0 =A0 =A0 $q4 =3D "";
>>>> }else{
>>>> =A0 =A0 =A0 $q4 =3D $rs->Fields(22);
>>>> }
>>>>
>>>> It produces this error:
>>>> Catchable fatal error: Object of class variant could not be converted
>>> to
>>>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>>>
>>>> Line 196 is:
>>>>
>>>> What am I doing wrong?
>>>>
>>>> Thanks!
>>>
>>> Just a thought... do you really mean $rs->Fields(22) or do you mean
>>> $rs->Fields[22]? The former is a function call and the latter is an
>>> array variable.
>>>
>>> Paul
>>>
>>> --
>>> Paul M. Foster
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 16:01:54 von Ashley Sheridan

On Wed, 2009-08-26 at 22:00 +0800, hack988 hack988 wrote:
> my god you use ado connect sorry I'm use php_mysql extentions for all
> mssql function.
> I'm never use ado connect before.
>
> 2009/8/26 David Stoltz :
> > Sorry - I don't know what you mean by DB class?
> >
> > I'm using Microsoft SQL 2000....with this code:
> >
> > > > //create an instance of the ADO connection object
> > $conn = new COM ("ADODB.Connection")
> > or die("Cannot start ADO");
> > //define connection string, specify database driver
> > $connStr = "PROVIDER=SQLOLEDB;SERVER=xxxx;UID=xxx;PWD=xxxx;DATABASE=xxx x";
> > $conn->open($connStr); //Open the connection to the database
> >
> > $query = "SELECT * FROM eval_evaluations WHERE id = ".$_POST["eval"];
> >
> > $rs = $conn->execute($query);
> >
> > echo $rs->Fields(22); //this is where that particular field is NULL, and produces the error
> >
> > ....
> >
> > -----Original Message-----
> > From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> > Sent: Wednesday, August 26, 2009 8:08 AM
> > To: David Stoltz
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] How to output a NULL field?
> >
> > Could you post your database's class to here?
> > I'm use mssql with php for several years and read NULL Fields is never
> > appear your case.
> >
> > 2009/8/26 David Stoltz :
> >> I tried that -it's in the first part of my message
> >>
> >>
> >> -----Original Message-----
> >> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> >> Sent: Wednesday, August 26, 2009 7:39 AM
> >> To: David Stoltz
> >> Cc: Paul M Foster; php-general@lists.php.net
> >> Subject: Re: [PHP] How to output a NULL field?
> >>
> >> use is_null() check it
> >>
> >> 2009/8/26 David Stoltz :
> >>> Paul,
> >>>
> >>> This all started because when I try this:
> >>>
> >>> Fields(22);?>
> >>>
> >>> It work fine, as long as there is a non-null value there, otherwise it
> >>> produces an error.
> >>>
> >>> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> >>> sure if that matters....
> >>>
> >>> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> >>> $rs recordset...that is, unless the value is NULL is the database - then
> >>> I get:
> >>>
> >>> Catchable fatal error: Object of class variant could not be converted to
> >>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
> >>>
> >>>
> >>> -----Original Message-----
> >>> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> >>> Sent: Tuesday, August 25, 2009 4:39 PM
> >>> To: php-general@lists.php.net
> >>> Subject: Re: [PHP] How to output a NULL field?
> >>>
> >>> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
> >>>
> >>>> $rs->Fields(22) equals a NULL in the database
> >>>>
> >>>> My Code:
> >>>>
> >>>> if(empty($rs->Fields(22))){
> >>>> $q4 = "";
> >>>> }else{
> >>>> $q4 = $rs->Fields(22);
> >>>> }
> >>>>
> >>>> Produces this error:
> >>>> Fatal error: Can't use method return value in write context in
> >>>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
> >>>>
> >>>> Line 32 is the "if" line...
> >>>>
> >>>> If I switch the code to (using is_null):
> >>>> if(is_null($rs->Fields(22))){
> >>>> $q4 = "";
> >>>> }else{
> >>>> $q4 = $rs->Fields(22);
> >>>> }
> >>>>
> >>>> It produces this error:
> >>>> Catchable fatal error: Object of class variant could not be converted
> >>> to
> >>>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
> >>>>
> >>>> Line 196 is:
> >>>>
> >>>> What am I doing wrong?
> >>>>
> >>>> Thanks!
> >>>
> >>> Just a thought... do you really mean $rs->Fields(22) or do you mean
> >>> $rs->Fields[22]? The former is a function call and the latter is an
> >>> array variable.
> >>>
> >>> Paul
> >>>
> >>> --
> >>> Paul M. Foster
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> >>
> >
>
That's impressive, but are you sure you don't use php_mssql extensions
instead? :p

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 16:12:50 von hack988 hack988

My code for mssql
please enable the php's mssql extentions.
it used like so many mysql class that you can find by google
------------------------------------------------------------ ---------------=
---------------------------------------
if(!defined('IN_WEB')) {
exit('Access Denied');
}
ini_set('mssql.datetimeconvert',0);//php>4.2.0 disable php's automatic
datetime convert
Class DB {
var $querynum=3D0;
var $mssql_link;
var $conn_link;
var $sp_link;
var $sp_name=3D'';
var $error_stop=3D0;
var $show_error=3D0;
var $dbhost;
var $dbuser;
var $dbpw;
var $dbname;
var $pconnect;
var $var_type=3Darray();
var $fields_name=3Darray();
var $last_error_msg=3D'';
var $phprunversion=3D'';
function DB() {
//define type for sp
$this->var_type['sp_bit']=3DSQLBIT;
$this->var_type['sp_tinyint']=3DSQLINT1;
$this->var_type['sp_smallint']=3DSQLINT2;
$this->var_type['sp_int']=3DSQLINT4;
$this->var_type['sp_bigint']=3DSQLVARCHAR;
$this->var_type['sp_real']=3DSQLFLT4;
$this->var_type['sp_float']=3DSQLFLT8;
$this->var_type['sp_float-null']=3DSQLFLTN;
$this->var_type['sp_smallmoney']=3DSQLFLT8;
$this->var_type['sp_money']=3DSQLFLT8;
$this->var_type['sp_money-null']=3DSQLFLT8;
$this->var_type['sp_char']=3DSQLCHAR;
$this->var_type['sp_varchar']=3DSQLVARCHAR;
$this->var_type['sp_text']=3DSQLTEXT;
$this->var_type['sp_datetime']=3DSQLINT4;
$this->phprunversion=3Dphpversion();
//end
}
/*>=3Dphp4.4.1,>=3Dphp5.1.1
a new paramate for if use newlink for connect,pconnect
*/
function rconnect($newlink=3Dfalse){//2007.03.01 by hack988 fix phpversion=
check
if($this->phprunversion >=3D '4.4.1' && $this->phprunversion < '5.0.0'
|| $this->phprunversion >=3D '5.1.1'){
return $this->rconnect4p($newlink);
}else{
return $this->rconnect3p();
}
}
function rconnect3p(){
$this->mssql_link =3D $this->pconnect==0 ?
mssql_connect($this->dbhost, $this->dbuser, $this->dbpw) :
mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw);
if(!$this->mssql_link){
$this->halt("connect
($this->pconnect)MSSQL($this->dbhost,$this->dbuser)failed!") ;
return false;
}else{
$this->conn_link=3D$this->mssql_link;
if($this->dbname) {
if (!@$this->select_db($this->dbname,$this->conn_link)){
$this->halt('can not use database '.$this->dbname);
return false;
}else{
return true;
}
}else{
return true;
}
}
}
function rconnect4p($newlink=3Dfalse){
$this->mssql_link =3D $this->pconnect==0 ?
mssql_connect($this->dbhost, $this->dbuser, $this->dbpw , $newlink) :
mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw, $newlink);
if(!$this->mssql_link){
$this->halt("reconect($this->pconnect)MSSQL($this->dbhost,$t his->dbuser)=
failed");
return false;
}else{
$this->conn_link=3D$this->mssql_link;
if($this->dbname) {
if (!@$this->select_db($this->dbname,$this->conn_link)){
$this->halt('can not use database '.$this->dbname);
return false;
}else{
return true;
}
}else{
return true;
}
}
}

function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect =3D
0,$auto_conn=3D0 ,$newlink=3Dfalse) {
$this->dbhost=3D$dbhost;
$this->dbuser=3D$dbuser;
$this->dbpw=3D$dbpw;
$this->dbname=3D$dbname;
$this->pconnect=3D$pconnect;
if($auto_conn){
return $this->rconnect($newlink);
}else{
return true;
}
}

function close() {
if($this->conn_link){
$result=3Dmssql_close($this->conn_link);
}else{
$result=3Dtrue;
}
$this->mssql_link=3D'';
$this->sp_link=3D'';
$this->conn_link=3D'';
return $result;
}

function select_db($dbname){
$this->mssql_link=3Dmssql_select_db("[".$dbname."]");
return $this->mssql_link;
}

function query($SQL,$method=3D'') {
if($method=='UNBUFFERED'){
mssql_query("SET NOCOUNT ON",$this->conn_link);
$this->mssql_link =3D mssql_query($SQL,$this->conn_link);
mssql_query("SET NOCOUNT OFF",$this->conn_link);
}else{
$this->mssql_link =3D mssql_query($SQL,$this->conn_link);
}

if (!$this->mssql_link) $this->halt('SQL query error: ' . $SQL);
$this->querynum++;
return $this->mssql_link;
}
=09
function get_one($sql,$prefix=3D""){
$query=3D$this->query($sql,'UNBUFFERED');
if(strlen($prefix)>0){
$this->get_fields_name();
$rs=3D$this->fetch_duplicate_array($query);
}else{
$rs =3D $this->fetch_array($query, MSSQL_ASSOC);
}
return $rs;
}

function seek($num,$link=3D''){
$link =3D empty($link) ? $this->mssql_link : $link;
return mssql_data_seek($link,$num);
}

function fetch_array($query, $result_type =3D MSSQL_ASSOC) {
return mssql_fetch_array($query, $result_type);
}

function fetch_duplicate_array($query, $prefix=3D"dup_") {
if(count($this->fields_name)<1) return false;
$fields=3D$this->fetch_array($query, MYSQL_NUM);
if(!$fields) return false;
$reternfields=3Darray();
foreach($fields AS $key=3D>$value){
if(isset($reternfields[$this->fields_name[$key]]))
$reternfields[$prefix.$this->fields_name[$key]]=3D$value;
else
$reternfields[$this->fields_name[$key]]=3D$fields[$key];
}
return $reternfields;
}

function affected_rows($link=3D'') {
$link=3D empty($link) ? $this->conn_link :$link;
return mssql_rows_affected($link);
}

function get_fields_name($link=3D''){
$link=3D empty($link) ? $this->mssql_link :$link;
$fieldscount=3D$this->num_fields($link);
for($i=3D0;$i<$fieldscount;$i++){
$field[$i]=3Dmssql_field_name($this->mssql_link,$i);
}
$this->fields_name=3D$field;
}

function num_rows($link=3D'') {
$link =3D empty($link) ? $this->mssql_link : $link;
$rows =3D mssql_num_rows($link);
return $rows;
}

function num_fields($query) {
return mssql_num_fields($query);
}

function sp_init($sp_name){
$this->sp_link=3Dmssql_init($sp_name,$this->conn_link);
!$this->sp_link && $this->halt('Init PROCEDURE Failed :' . $sp_name);
$this->sp_name=3D$sp_name;
return $this->sp_link;
}

function sp_bind($parameter,&$var,$type,$if_out=3Dfalse,$if_null=3Dfa lse){
if(!$this->sp_link){
$this->halt('Can not bind var for PROCEDURE' . $parameter);
return false;
}else{
if(!mssql_bind($this->sp_link,$parameter,$var,$this->var_typ e[$type],$if=
_out,$if_null)){
$this->halt('PROCEDURE var binding failed' .
$parameter.$this->var_type[$type]);
return false;
}else{
return true;
}
}
}

function sp_execute($skipout,$sp_link=3D''){
$this->sp_link=3D$sp_link? $sp_link : $this->sp_link;
$this->mssql_link=3Dmssql_execute($this->sp_link,$skipout);
if (!$this->mssql_link) $this->halt('exec PROCEDURE failed: ' . $SQL);
$this->querynum++;
return $this->mssql_link;
}

function sp_free_statement($sp_link=3D''){
$this->sp_link=3D$sp_link? $sp_link : $this->sp_link;
if(!mssql_free_statement($this->sp_link)){
$this->halt('free memory failed (PROCEDURE)£º'.$this->sp_name);
return false;
}else{
$this->sp_link=3D'';
return true;
}
}

function free_result($query) {
return mssql_free_result($query);
}

function insert_id() {
$rs =3D $this->get_one("SELECT @@IDENTITY AS [insertid]");
if($rs)
return $rs['insertid'];
else
return false;
}

function halt($msg=3D'') {
if($this->show_error){
echo date("Y-m-d H:i:s",time())."
\n";
echo $msg."
\n";
$this->last_error_msg=3D"SQL Server
Msg:".nl2br(mssql_get_last_message())."
\n";
echo $this->last_error_msg;
$this->last_error_msg =3D $msg.$this->last_error_msg;
}
$this->error_stop && exit;
}
}
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 16:50:08 von David Stoltz

Wow - thanks for the code, but it's over my head at this point.

I'm a PHP newbie....I typically use ASP Classic, but I realize I need to learn PHP for ongoing development. Problem is, we don't have MySQL here, so I have to fumble my way through with MS SQL.

Thanks!


-----Original Message-----
From: hack988 hack988 [mailto:hack988@dev.htwap.com]
Sent: Wednesday, August 26, 2009 10:13 AM
To: ash@ashleysheridan.co.uk
Cc: David Stoltz; php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

My code for mssql
please enable the php's mssql extentions.
it used like so many mysql class that you can find by google
------------------------------------------------------------ ------------------------------------------------------
if(!defined('IN_WEB')) {
exit('Access Denied');
}
ini_set('mssql.datetimeconvert',0);//php>4.2.0 disable php's automatic
datetime convert
Class DB {
var $querynum=0;
var $mssql_link;
var $conn_link;
var $sp_link;
var $sp_name='';
var $error_stop=0;
var $show_error=0;
var $dbhost;
var $dbuser;
var $dbpw;
var $dbname;
var $pconnect;
var $var_type=array();
var $fields_name=array();
var $last_error_msg='';
var $phprunversion='';
function DB() {
//define type for sp
$this->var_type['sp_bit']=SQLBIT;
$this->var_type['sp_tinyint']=SQLINT1;
$this->var_type['sp_smallint']=SQLINT2;
$this->var_type['sp_int']=SQLINT4;
$this->var_type['sp_bigint']=SQLVARCHAR;
$this->var_type['sp_real']=SQLFLT4;
$this->var_type['sp_float']=SQLFLT8;
$this->var_type['sp_float-null']=SQLFLTN;
$this->var_type['sp_smallmoney']=SQLFLT8;
$this->var_type['sp_money']=SQLFLT8;
$this->var_type['sp_money-null']=SQLFLT8;
$this->var_type['sp_char']=SQLCHAR;
$this->var_type['sp_varchar']=SQLVARCHAR;
$this->var_type['sp_text']=SQLTEXT;
$this->var_type['sp_datetime']=SQLINT4;
$this->phprunversion=phpversion();
//end
}
/*>=php4.4.1,>=php5.1.1
a new paramate for if use newlink for connect,pconnect
*/
function rconnect($newlink=false){//2007.03.01 by hack988 fix phpversion check
if($this->phprunversion >= '4.4.1' && $this->phprunversion < '5.0.0'
|| $this->phprunversion >= '5.1.1'){
return $this->rconnect4p($newlink);
}else{
return $this->rconnect3p();
}
}
function rconnect3p(){
$this->mssql_link = $this->pconnect==0 ?
mssql_connect($this->dbhost, $this->dbuser, $this->dbpw) :
mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw);
if(!$this->mssql_link){
$this->halt("connect
($this->pconnect)MSSQL($this->dbhost,$this->dbuser)failed!") ;
return false;
}else{
$this->conn_link=$this->mssql_link;
if($this->dbname) {
if (!@$this->select_db($this->dbname,$this->conn_link)){
$this->halt('can not use database '.$this->dbname);
return false;
}else{
return true;
}
}else{
return true;
}
}
}
function rconnect4p($newlink=false){
$this->mssql_link = $this->pconnect==0 ?
mssql_connect($this->dbhost, $this->dbuser, $this->dbpw , $newlink) :
mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw, $newlink);
if(!$this->mssql_link){
$this->halt("reconect($this->pconnect)MSSQL($this->dbhost,$t his->dbuser)failed");
return false;
}else{
$this->conn_link=$this->mssql_link;
if($this->dbname) {
if (!@$this->select_db($this->dbname,$this->conn_link)){
$this->halt('can not use database '.$this->dbname);
return false;
}else{
return true;
}
}else{
return true;
}
}
}

function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect =
0,$auto_conn=0 ,$newlink=false) {
$this->dbhost=$dbhost;
$this->dbuser=$dbuser;
$this->dbpw=$dbpw;
$this->dbname=$dbname;
$this->pconnect=$pconnect;
if($auto_conn){
return $this->rconnect($newlink);
}else{
return true;
}
}

function close() {
if($this->conn_link){
$result=mssql_close($this->conn_link);
}else{
$result=true;
}
$this->mssql_link='';
$this->sp_link='';
$this->conn_link='';
return $result;
}

function select_db($dbname){
$this->mssql_link=mssql_select_db("[".$dbname."]");
return $this->mssql_link;
}

function query($SQL,$method='') {
if($method=='UNBUFFERED'){
mssql_query("SET NOCOUNT ON",$this->conn_link);
$this->mssql_link = mssql_query($SQL,$this->conn_link);
mssql_query("SET NOCOUNT OFF",$this->conn_link);
}else{
$this->mssql_link = mssql_query($SQL,$this->conn_link);
}

if (!$this->mssql_link) $this->halt('SQL query error: ' . $SQL);
$this->querynum++;
return $this->mssql_link;
}

function get_one($sql,$prefix=""){
$query=$this->query($sql,'UNBUFFERED');
if(strlen($prefix)>0){
$this->get_fields_name();
$rs=$this->fetch_duplicate_array($query);
}else{
$rs = $this->fetch_array($query, MSSQL_ASSOC);
}
return $rs;
}

function seek($num,$link=''){
$link = empty($link) ? $this->mssql_link : $link;
return mssql_data_seek($link,$num);
}

function fetch_array($query, $result_type = MSSQL_ASSOC) {
return mssql_fetch_array($query, $result_type);
}

function fetch_duplicate_array($query, $prefix="dup_") {
if(count($this->fields_name)<1) return false;
$fields=$this->fetch_array($query, MYSQL_NUM);
if(!$fields) return false;
$reternfields=array();
foreach($fields AS $key=>$value){
if(isset($reternfields[$this->fields_name[$key]]))
$reternfields[$prefix.$this->fields_name[$key]]=$value;
else
$reternfields[$this->fields_name[$key]]=$fields[$key];
}
return $reternfields;
}

function affected_rows($link='') {
$link= empty($link) ? $this->conn_link :$link;
return mssql_rows_affected($link);
}

function get_fields_name($link=''){
$link= empty($link) ? $this->mssql_link :$link;
$fieldscount=$this->num_fields($link);
for($i=0;$i<$fieldscount;$i++){
$field[$i]=mssql_field_name($this->mssql_link,$i);
}
$this->fields_name=$field;
}

function num_rows($link='') {
$link = empty($link) ? $this->mssql_link : $link;
$rows = mssql_num_rows($link);
return $rows;
}

function num_fields($query) {
return mssql_num_fields($query);
}

function sp_init($sp_name){
$this->sp_link=mssql_init($sp_name,$this->conn_link);
!$this->sp_link && $this->halt('Init PROCEDURE Failed :' . $sp_name);
$this->sp_name=$sp_name;
return $this->sp_link;
}

function sp_bind($parameter,&$var,$type,$if_out=false,$if_null=false) {
if(!$this->sp_link){
$this->halt('Can not bind var for PROCEDURE' . $parameter);
return false;
}else{
if(!mssql_bind($this->sp_link,$parameter,$var,$this->var_typ e[$type],$if_out,$if_null)){
$this->halt('PROCEDURE var binding failed' .
$parameter.$this->var_type[$type]);
return false;
}else{
return true;
}
}
}

function sp_execute($skipout,$sp_link=''){
$this->sp_link=$sp_link? $sp_link : $this->sp_link;
$this->mssql_link=mssql_execute($this->sp_link,$skipout);
if (!$this->mssql_link) $this->halt('exec PROCEDURE failed: ' . $SQL);
$this->querynum++;
return $this->mssql_link;
}

function sp_free_statement($sp_link=''){
$this->sp_link=$sp_link? $sp_link : $this->sp_link;
if(!mssql_free_statement($this->sp_link)){
$this->halt('free memory failed (PROCEDURE)$B!'(J'.$this->sp_name);
return false;
}else{
$this->sp_link='';
return true;
}
}

function free_result($query) {
return mssql_free_result($query);
}

function insert_id() {
$rs = $this->get_one("SELECT @@IDENTITY AS [insertid]");
if($rs)
return $rs['insertid'];
else
return false;
}

function halt($msg='') {
if($this->show_error){
echo date("Y-m-d H:i:s",time())."
\n";
echo $msg."
\n";
$this->last_error_msg="SQL Server
Msg:".nl2br(mssql_get_last_message())."
\n";
echo $this->last_error_msg;
$this->last_error_msg = $msg.$this->last_error_msg;
}
$this->error_stop && exit;
}
}
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 16:52:00 von Ashley Sheridan

On Wed, 2009-08-26 at 10:50 -0400, David Stoltz wrote:
> Wow - thanks for the code, but it's over my head at this point.
>=20
> I'm a PHP newbie....I typically use ASP Classic, but I realize I need to =
learn PHP for ongoing development. Problem is, we don't have MySQL here, so=
I have to fumble my way through with MS SQL.
>=20
> Thanks!
>=20
>=20
> -----Original Message-----
> From: hack988 hack988 [mailto:hack988@dev.htwap.com]=20
> Sent: Wednesday, August 26, 2009 10:13 AM
> To: ash@ashleysheridan.co.uk
> Cc: David Stoltz; php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>=20
> My code for mssql
> please enable the php's mssql extentions.
> it used like so many mysql class that you can find by google
> ------------------------------------------------------------ -------------=
-----------------------------------------
> > if(!defined('IN_WEB')) {
> exit('Access Denied');
> }
> ini_set('mssql.datetimeconvert',0);//php>4.2.0 disable php's automatic
> datetime convert
> Class DB {
> var $querynum=3D0;
> var $mssql_link;
> var $conn_link;
> var $sp_link;
> var $sp_name=3D'';
> var $error_stop=3D0;
> var $show_error=3D0;
> var $dbhost;
> var $dbuser;
> var $dbpw;
> var $dbname;
> var $pconnect;
> var $var_type=3Darray();
> var $fields_name=3Darray();
> var $last_error_msg=3D'';
> var $phprunversion=3D'';
> function DB() {
> //define type for sp
> $this->var_type['sp_bit']=3DSQLBIT;
> $this->var_type['sp_tinyint']=3DSQLINT1;
> $this->var_type['sp_smallint']=3DSQLINT2;
> $this->var_type['sp_int']=3DSQLINT4;
> $this->var_type['sp_bigint']=3DSQLVARCHAR;
> $this->var_type['sp_real']=3DSQLFLT4;
> $this->var_type['sp_float']=3DSQLFLT8;
> $this->var_type['sp_float-null']=3DSQLFLTN;
> $this->var_type['sp_smallmoney']=3DSQLFLT8;
> $this->var_type['sp_money']=3DSQLFLT8;
> $this->var_type['sp_money-null']=3DSQLFLT8;
> $this->var_type['sp_char']=3DSQLCHAR;
> $this->var_type['sp_varchar']=3DSQLVARCHAR;
> $this->var_type['sp_text']=3DSQLTEXT;
> $this->var_type['sp_datetime']=3DSQLINT4;
> $this->phprunversion=3Dphpversion();
> //end
> }
> /*>=3Dphp4.4.1,>=3Dphp5.1.1
> a new paramate for if use newlink for connect,pconnect
> */
> function rconnect($newlink=3Dfalse){//2007.03.01 by hack988 fix phpversi=
on check
> if($this->phprunversion >=3D '4.4.1' && $this->phprunversion < '5.0.0'
> || $this->phprunversion >=3D '5.1.1'){
> return $this->rconnect4p($newlink);
> }else{
> return $this->rconnect3p();
> }
> }
> function rconnect3p(){
> $this->mssql_link =3D $this->pconnect==0 ?
> mssql_connect($this->dbhost, $this->dbuser, $this->dbpw) :
> mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw);
> if(!$this->mssql_link){
> $this->halt("connect
> ($this->pconnect)MSSQL($this->dbhost,$this->dbuser)failed!") ;
> return false;
> }else{
> $this->conn_link=3D$this->mssql_link;
> if($this->dbname) {
> if (!@$this->select_db($this->dbname,$this->conn_link)){
> $this->halt('can not use database '.$this->dbname);
> return false;
> }else{
> return true;
> }
> }else{
> return true;
> }
> }
> }
> function rconnect4p($newlink=3Dfalse){
> $this->mssql_link =3D $this->pconnect==0 ?
> mssql_connect($this->dbhost, $this->dbuser, $this->dbpw , $newlink) :
> mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpw, $newlink);
> if(!$this->mssql_link){
> $this->halt("reconect($this->pconnect)MSSQL($this->dbhost,$t his->dbuse=
r)failed");
> return false;
> }else{
> $this->conn_link=3D$this->mssql_link;
> if($this->dbname) {
> if (!@$this->select_db($this->dbname,$this->conn_link)){
> $this->halt('can not use database '.$this->dbname);
> return false;
> }else{
> return true;
> }
> }else{
> return true;
> }
> }
> }
>=20
> function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect =3D
> 0,$auto_conn=3D0 ,$newlink=3Dfalse) {
> $this->dbhost=3D$dbhost;
> $this->dbuser=3D$dbuser;
> $this->dbpw=3D$dbpw;
> $this->dbname=3D$dbname;
> $this->pconnect=3D$pconnect;
> if($auto_conn){
> return $this->rconnect($newlink);
> }else{
> return true;
> }
> }
>=20
> function close() {
> if($this->conn_link){
> $result=3Dmssql_close($this->conn_link);
> }else{
> $result=3Dtrue;
> }
> $this->mssql_link=3D'';
> $this->sp_link=3D'';
> $this->conn_link=3D'';
> return $result;
> }
>=20
> function select_db($dbname){
> $this->mssql_link=3Dmssql_select_db("[".$dbname."]");
> return $this->mssql_link;
> }
>=20
> function query($SQL,$method=3D'') {
> if($method=='UNBUFFERED'){
> mssql_query("SET NOCOUNT ON",$this->conn_link);
> $this->mssql_link =3D mssql_query($SQL,$this->conn_link);
> mssql_query("SET NOCOUNT OFF",$this->conn_link);
> }else{
> $this->mssql_link =3D mssql_query($SQL,$this->conn_link);
> }
>=20
> if (!$this->mssql_link) $this->halt('SQL query error: ' . $SQL);
> $this->querynum++;
> return $this->mssql_link;
> }
> =09
> function get_one($sql,$prefix=3D""){
> $query=3D$this->query($sql,'UNBUFFERED');
> if(strlen($prefix)>0){
> $this->get_fields_name();
> $rs=3D$this->fetch_duplicate_array($query);
> }else{
> $rs =3D $this->fetch_array($query, MSSQL_ASSOC);
> }
> return $rs;
> }
>=20
> function seek($num,$link=3D''){
> $link =3D empty($link) ? $this->mssql_link : $link;
> return mssql_data_seek($link,$num);
> }
>=20
> function fetch_array($query, $result_type =3D MSSQL_ASSOC) {
> return mssql_fetch_array($query, $result_type);
> }
>=20
> function fetch_duplicate_array($query, $prefix=3D"dup_") {
> if(count($this->fields_name)<1) return false;
> $fields=3D$this->fetch_array($query, MYSQL_NUM);
> if(!$fields) return false;
> $reternfields=3Darray();
> foreach($fields AS $key=3D>$value){
> if(isset($reternfields[$this->fields_name[$key]]))
> $reternfields[$prefix.$this->fields_name[$key]]=3D$value;
> else
> $reternfields[$this->fields_name[$key]]=3D$fields[$key];
> }
> return $reternfields;
> }
>=20
> function affected_rows($link=3D'') {
> $link=3D empty($link) ? $this->conn_link :$link;
> return mssql_rows_affected($link);
> }
>=20
> function get_fields_name($link=3D''){
> $link=3D empty($link) ? $this->mssql_link :$link;
> $fieldscount=3D$this->num_fields($link);
> for($i=3D0;$i<$fieldscount;$i++){
> $field[$i]=3Dmssql_field_name($this->mssql_link,$i);
> }
> $this->fields_name=3D$field;
> }
>=20
> function num_rows($link=3D'') {
> $link =3D empty($link) ? $this->mssql_link : $link;
> $rows =3D mssql_num_rows($link);
> return $rows;
> }
>=20
> function num_fields($query) {
> return mssql_num_fields($query);
> }
>=20
> function sp_init($sp_name){
> $this->sp_link=3Dmssql_init($sp_name,$this->conn_link);
> !$this->sp_link && $this->halt('Init PROCEDURE Failed :' . $sp_name);
> $this->sp_name=3D$sp_name;
> return $this->sp_link;
> }
>=20
> function sp_bind($parameter,&$var,$type,$if_out=3Dfalse,$if_null=3Dfa lse=
){
> if(!$this->sp_link){
> $this->halt('Can not bind var for PROCEDURE' . $parameter);
> return false;
> }else{
> if(!mssql_bind($this->sp_link,$parameter,$var,$this->var_typ e[$type],$=
if_out,$if_null)){
> $this->halt('PROCEDURE var binding failed' .
> $parameter.$this->var_type[$type]);
> return false;
> }else{
> return true;
> }
> }
> }
>=20
> function sp_execute($skipout,$sp_link=3D''){
> $this->sp_link=3D$sp_link? $sp_link : $this->sp_link;
> $this->mssql_link=3Dmssql_execute($this->sp_link,$skipout);
> if (!$this->mssql_link) $this->halt('exec PROCEDURE failed: ' . $SQL);
> $this->querynum++;
> return $this->mssql_link;
> }
>=20
> function sp_free_statement($sp_link=3D''){
> $this->sp_link=3D$sp_link? $sp_link : $this->sp_link;
> if(!mssql_free_statement($this->sp_link)){
> $this->halt('free memory failed (PROCEDURE)ï¼=9A'.$this->sp_name);
> return false;
> }else{
> $this->sp_link=3D'';
> return true;
> }
> }
>=20
> function free_result($query) {
> return mssql_free_result($query);
> }
>=20
> function insert_id() {
> $rs =3D $this->get_one("SELECT @@IDENTITY AS [insertid]");
> if($rs)
> return $rs['insertid'];
> else
> return false;
> }
>=20
> function halt($msg=3D'') {
> if($this->show_error){
> echo date("Y-m-d H:i:s",time())."
Â¥n";
> echo $msg."
Â¥n";
> $this->last_error_msg=3D"SQL Server
> Msg:".nl2br(mssql_get_last_message())."
Â¥n";
> echo $this->last_error_msg;
> $this->last_error_msg =3D $msg.$this->last_error_msg;
> }
> $this->error_stop && exit;
> }
> }
> ?>
>=20
You should try and see if you can get it installed there, as it will
work on Windows servers. I've found it generally to be faster than MS
SQL, and the choice of different database engines for each table gives
you a LOT of flexibility for the future too. Also, MySQL offers a bit
more functionality I've found.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:01:02 von Andrew Ballard

On Wed, Aug 26, 2009 at 10:52 AM, Ashley
Sheridan wrote:
> You should try and see if you can get it installed there, as it will
> work on Windows servers. I've found it generally to be faster than MS
> SQL, and the choice of different database engines for each table gives
> you a LOT of flexibility for the future too. Also, MySQL offers a bit
> more functionality I've found.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

To be fair, I've not had found any performance problems when using SQL
Server. And, while there is one main feature MySQL has that I really
miss in SQL Server (the LIMIT clause), I miss enforcement of CHECK
constraints in MySQL. (I suppose I could implement them via triggers,
but that just seems messy to me.)

I'm all for flexibility, though.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: How to output a NULL field?

am 26.08.2009 18:06:33 von Andrew Ballard

On Tue, Aug 25, 2009 at 3:22 PM, Shawn McKenzie wrote:
> First off, if the value is NULL in the database then in PHP it will be
> the string "NULL" and not a null value as far as I remember.

I've not seen this happen. I've found, depending on the database and
the data access library used to interface with it that NULL usually
comes back as either the PHP NULL value or an empty string.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:06:41 von hack988 hack988

Mysql,mssql has its own feature,you can't say Mysql is better than
Mssql or Mssql it better than Mysql,Is'nt is?
My the Way ,Mssql support Top n,m form mssql 2005 :)

2009/8/27 Andrew Ballard :
> On Wed, Aug 26, 2009 at 10:52 AM, Ashley
> Sheridan wrote:
>> You should try and see if you can get it installed there, as it will
>> work on Windows servers. I've found it generally to be faster than MS
>> SQL, and the choice of different database engines for each table gives
>> you a LOT of flexibility for the future too. Also, MySQL offers a bit
>> more functionality I've found.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>
> To be fair, I've not had found any performance problems when using SQL
> Server. And, while there is one main feature MySQL has that I really
> miss in SQL Server (the LIMIT clause), I miss enforcement of CHECK
> constraints in MySQL. (I suppose I could implement them via triggers,
> but that just seems messy to me.)
>
> I'm all for flexibility, though.
>
> Andrew
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:13:50 von Andrew Ballard

On Wed, Aug 26, 2009 at 9:51 AM, David Stoltz wrote:
> Sorry - I don't know what you mean by DB class?
>
> I'm using Microsoft SQL 2000....with this code:
>
> > //create an instance of the  ADO connection object
> $conn =3D new COM ("ADODB.Connection")
>  or die("Cannot start ADO");
> //define connection string, specify database driver
> $connStr =3D "PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DATA =
BASE=3Dxxxx";
> $conn->open($connStr); //Open the connection to the database
>
> $query =3D "SELECT * FROM eval_evaluations WHERE id =3D ".$_POST["eval"];
>
> $rs =3D $conn->execute($query);
>
> echo $rs->Fields(22); //this is where that particular field is NULL, and =
produces the error
>
> ....
>

Because you are using COM, you can't use PHP's empty(), isset(), or
is_null() in your if(...) statement. I've not used COM for much in
PHP, but I think you'll have to do something like this:

switch (variant_get_type($rs->Fields(22)) {
case VT_EMPTY:
case VT_NULL:
$q4 =3D '';
break;

case VT_UI1:

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:18:04 von hack988 hack988

Com function is just for Windows,I don't kown why some body like use it.:(

2009/8/27 Andrew Ballard :
> On Wed, Aug 26, 2009 at 9:51 AM, David Stoltz wrote:
>> Sorry - I don't know what you mean by DB class?
>>
>> I'm using Microsoft SQL 2000....with this code:
>>
>> >> //create an instance of the =A0ADO connection object
>> $conn =3D new COM ("ADODB.Connection")
>> =A0or die("Cannot start ADO");
>> //define connection string, specify database driver
>> $connStr =3D "PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DAT=
ABASE=3Dxxxx";
>> $conn->open($connStr); //Open the connection to the database
>>
>> $query =3D "SELECT * FROM eval_evaluations WHERE id =3D ".$_POST["eval"]=
;
>>
>> $rs =3D $conn->execute($query);
>>
>> echo $rs->Fields(22); //this is where that particular field is NULL, and=
produces the error
>>
>> ....
>>
>
> Because you are using COM, you can't use PHP's empty(), isset(), or
> is_null() in your if(...) statement. I've not used COM for much in
> PHP, but I think you'll have to do something like this:
>
> switch (variant_get_type($rs->Fields(22)) {
> =A0 =A0case VT_EMPTY:
> =A0 =A0case VT_NULL:
> =A0 =A0 =A0 =A0$q4 =3D '';
> =A0 =A0 =A0 =A0break;
>
> =A0 =A0case VT_UI1:
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:18:09 von Andrew Ballard

On Wed, Aug 26, 2009 at 12:13 PM, Andrew Ballard wrote:
> On Wed, Aug 26, 2009 at 9:51 AM, David Stoltz wrote:
>> Sorry - I don't know what you mean by DB class?
>>
>> I'm using Microsoft SQL 2000....with this code:
>>
>> >> //create an instance of the  ADO connection object
>> $conn =3D new COM ("ADODB.Connection")
>>  or die("Cannot start ADO");
>> //define connection string, specify database driver
>> $connStr =3D "PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DAT=
ABASE=3Dxxxx";
>> $conn->open($connStr); //Open the connection to the database
>>
>> $query =3D "SELECT * FROM eval_evaluations WHERE id =3D ".$_POST["eval"]=
;
>>
>> $rs =3D $conn->execute($query);
>>
>> echo $rs->Fields(22); //this is where that particular field is NULL, and=
produces the error
>>
>> ....
>>
>
> Because you are using COM, you can't use PHP's empty(), isset(), or
> is_null() in your if(...) statement. I've not used COM for much in
> PHP, but I think you'll have to do something like this:
>
> switch (variant_get_type($rs->Fields(22)) {
>    case VT_EMPTY:
>    case VT_NULL:
>        $q4 =3D '';
>        break;
>
>    case VT_UI1:
>

blast ... hit some key and Gmail just sent what I had typed so far.

At any rate, hopefully you can get the idea from that last post. Look
at this reference for handling different types returned from COM:

http://www.php.net/manual/en/com.constants.php


I would also suggest looking into a PHP library for querying SQL
Server rather than relying on COM. There are several, some work better
than others. I've found that the SQL Server Driver for PHP works best
for what I use. It is documented as being for 2005 and newer, but I
have been able to use it just fine with 2000 as well.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:19:22 von Andrew Ballard

On Wed, Aug 26, 2009 at 12:06 PM, hack988 hack988 wrote:
> Mysql,mssql has its own feature,you can't say Mysql is better than
> Mssql or Mssql it better than Mysql,Is'nt is?
> My the Way ,Mssql support Top n,m form mssql 2005 :)
>

Perhaps, but the OP said he's using SQL Server 2000.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:25:35 von hack988 hack988

I'm sorry for my poor English,what is OP? I don't kown what is OP mean.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:26:05 von Ashley Sheridan

On Thu, 2009-08-27 at 00:25 +0800, hack988 hack988 wrote:
> I'm sorry for my poor English,what is OP? I don't kown what is OP mean.
>

It's basically the original person who asked the question.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: How to output a NULL field?

am 26.08.2009 18:31:40 von David Stoltz

I'm using COM because I don't know what else to use ;-)

Like I said, I'm new to PHP. Here is another way I communicate with the =
database, let me know if this is a better way (it requires a stored =
procedure):

//Assign the server connection to a variable
$connect =3D mssql_connect(SERVER,1433', USER, 'PASSWORD');
=20
//Select your database and reference the connection
mssql_select_db('DATABASE', $connect);

// Create a new stored prodecure
$stmt =3D mssql_init('StoredProcedureName');

// Bind the field names
mssql_bind($stmt, '@category',$cat,SQLINT4,false,false,4);
mssql_bind($stmt, '@userid',$userid,SQLINT4,false,false,4);
mssql_bind($stmt, '@passwordtitle',$pname,SQLVARCHAR,false,false,100);
mssql_bind($stmt, =
'@password',$encrypted_data,SQLVARCHAR,false,false,1000);
mssql_bind($stmt, '@alt',$alt,SQLVARCHAR,false,false,150);
mssql_bind($stmt, '@desc',$desc,SQLVARCHAR,false,false,100);

// Execute=20
mssql_execute($stmt);


-----Original Message-----
From: hack988 hack988 [mailto:hack988@dev.htwap.com]=20
Sent: Wednesday, August 26, 2009 12:18 PM
To: Andrew Ballard
Cc: David Stoltz; php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

Com function is just for Windows,I don't kown why some body like use =
it.:(

2009/8/27 Andrew Ballard :
> On Wed, Aug 26, 2009 at 9:51 AM, David Stoltz wrote:
>> Sorry - I don't know what you mean by DB class?
>>
>> I'm using Microsoft SQL 2000....with this code:
>>
>> >> //create an instance of the =A0ADO connection object
>> $conn =3D new COM ("ADODB.Connection")
>> =A0or die("Cannot start ADO");
>> //define connection string, specify database driver
>> $connStr =3D =
"PROVIDER=3DSQLOLEDB;SERVER=3Dxxxx;UID=3Dxxx;PWD=3Dxxxx;DATA BASE=3Dxxxx";=

>> $conn->open($connStr); //Open the connection to the database
>>
>> $query =3D "SELECT * FROM eval_evaluations WHERE id =3D =
".$_POST["eval"];
>>
>> $rs =3D $conn->execute($query);
>>
>> echo $rs->Fields(22); //this is where that particular field is NULL, =
and produces the error
>>
>> ....
>>
>
> Because you are using COM, you can't use PHP's empty(), isset(), or
> is_null() in your if(...) statement. I've not used COM for much in
> PHP, but I think you'll have to do something like this:
>
> switch (variant_get_type($rs->Fields(22)) {
> =A0 =A0case VT_EMPTY:
> =A0 =A0case VT_NULL:
> =A0 =A0 =A0 =A0$q4 =3D '';
> =A0 =A0 =A0 =A0break;
>
> =A0 =A0case VT_UI1:
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:38:16 von Paul M Foster

On Thu, Aug 27, 2009 at 12:25:35AM +0800, hack988 hack988 wrote:

> I'm sorry for my poor English,what is OP? I don't kown what is OP mean.

OP = "Original Poster". That's usually the person who first started
(posted) a thread on a list.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

How to output a NULL field?

am 26.08.2009 18:48:12 von David Stoltz

Looking on Amazon and other book sites, I can't even find a book for
"PHP and MS SQL"...

It's all "PHP and MySQL"...

Should I avoid developing PHP application with MS SQL databases?


-----Original Message-----
From: Paul M Foster [mailto:paulf@quillandmouse.com]=20
Sent: Wednesday, August 26, 2009 12:38 PM
To: php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

On Thu, Aug 27, 2009 at 12:25:35AM +0800, hack988 hack988 wrote:

> I'm sorry for my poor English,what is OP? I don't kown what is OP
mean.

OP =3D "Original Poster". That's usually the person who first started
(posted) a thread on a list.

Paul

--=20
Paul M. Foster

--=20
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 18:51:11 von Ashley Sheridan

On Wed, 2009-08-26 at 12:48 -0400, David Stoltz wrote:
> Looking on Amazon and other book sites, I can't even find a book for
> "PHP and MS SQL"...
>
> It's all "PHP and MySQL"...
>
> Should I avoid developing PHP application with MS SQL databases?
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Wednesday, August 26, 2009 12:38 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Thu, Aug 27, 2009 at 12:25:35AM +0800, hack988 hack988 wrote:
>
> > I'm sorry for my poor English,what is OP? I don't kown what is OP
> mean.
>
> OP = "Original Poster". That's usually the person who first started
> (posted) a thread on a list.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I'd definately recommend going down the MySQL route, but it may well
depend on what sort of apps you are developing and where your target
markets lie.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: How to output a NULL field?

am 26.08.2009 20:02:22 von Phpster

On Wed, Aug 26, 2009 at 12:06 PM, Andrew Ballard wrote:
> On Tue, Aug 25, 2009 at 3:22 PM, Shawn McKenzie wrote:
>> First off, if the value is NULL in the database then in PHP it will be
>> the string "NULL" and not a null value as far as I remember.
>
> I've not seen this happen. I've found, depending on the database and
> the data access library used to interface with it that NULL usually
> comes back as either the PHP NULL value or an empty string.
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

One option then, might be to format the result with SQL using a CASE
WHEN THEN statement or ISNULL / IFNULL to set it to empty string

--

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 26.08.2009 20:20:46 von Paul M Foster

On Wed, Aug 26, 2009 at 12:48:12PM -0400, David Stoltz wrote:

> Looking on Amazon and other book sites, I can't even find a book for
> "PHP and MS SQL"...
>
> It's all "PHP and MySQL"...
>
> Should I avoid developing PHP application with MS SQL databases?

My *opinion* is that you should avoid Microsoft products whenever
possible. BTW, you can also find books on PHP and PostgreSQL, which,
also in my *opinion* is a superior choice over MySQL.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to output a NULL field?

am 27.08.2009 03:30:49 von Phpster

On Aug 26, 2009, at 12:31 PM, "David Stoltz" wrote:

> I'm using COM because I don't know what else to use ;-)
>
> Like I said, I'm new to PHP. Here is another way I communicate with
> the database, let me know if this is a better way (it requires a
> stored procedure):
>
> //Assign the server connection to a variable
> $connect = mssql_connect(SERVER,1433', USER, 'PASSWORD');
>
> //Select your database and reference the connection
> mssql_select_db('DATABASE', $connect);
>
> // Create a new stored prodecure
> $stmt = mssql_init('StoredProcedureName');
>
> // Bind the field names
> mssql_bind($stmt, '@category',$cat,SQLINT4,false,false,4);
> mssql_bind($stmt, '@userid',$userid,SQLINT4,false,false,4);
> mssql_bind($stmt, '@passwordtitle',$pname,SQLVARCHAR,false,false,100);
> mssql_bind($stmt, '@password',$encrypted_data,SQLVARCHAR,false,false,
> 1000);
> mssql_bind($stmt, '@alt',$alt,SQLVARCHAR,false,false,150);
> mssql_bind($stmt, '@desc',$desc,SQLVARCHAR,false,false,100);
>
> // Execute
> mssql_execute($stmt);
>
>
> -----Original Message-----
> From: hack988 hack988 [mailto:hack988@dev.htwap.com]
> Sent: Wednesday, August 26, 2009 12:18 PM
> To: Andrew Ballard
> Cc: David Stoltz; php-general@lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> Com function is just for Windows,I don't kown why some body like use
> it.:(
>
> 2009/8/27 Andrew Ballard :
>> On Wed, Aug 26, 2009 at 9:51 AM, David Stoltz wrote:
>>> Sorry - I don't know what you mean by DB class?
>>>
>>> I'm using Microsoft SQL 2000....with this code:
>>>
>>> >>> //create an instance of the ADO connection object
>>> $conn = new COM ("ADODB.Connection")
>>> or die("Cannot start ADO");
>>> //define connection string, specify database driver
>>> $connStr =
>>> "PROVIDER=SQLOLEDB;SERVER=xxxx;UID=xxx;PWD=xxxx;DATABASE=xxx x";
>>> $conn->open($connStr); //Open the connection to the database
>>>
>>> $query = "SELECT * FROM eval_evaluations WHERE id = ".$_POST
>>> ["eval"];
>>>
>>> $rs = $conn->execute($query);
>>>
>>> echo $rs->Fields(22); //this is where that particular field is
>>> NULL, and produces the error
>>>
>>> ....
>>>
>>
>> Because you are using COM, you can't use PHP's empty(), isset(), or
>> is_null() in your if(...) statement. I've not used COM for much in
>> PHP, but I think you'll have to do something like this:
>>
>> switch (variant_get_type($rs->Fields(22)) {
>> case VT_EMPTY:
>> case VT_NULL:
>> $q4 = '';
>> break;
>>
>> case VT_UI1:
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

MS has developed and released a new version of the mssql drivers for
php. It might be worth investigating that to see ifthat firs your needs.

Bastien

Sent from my iPod

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: How to output a NULL field?

am 27.08.2009 14:37:58 von David Stoltz

You're a genius - that works!!!!!


-----Original Message-----
From: Bastien Koert [mailto:phpster@gmail.com]=20
Sent: Wednesday, August 26, 2009 2:02 PM
To: Andrew Ballard
Cc: Shawn McKenzie; php-general@lists.php.net; David Stoltz
Subject: Re: [PHP] Re: How to output a NULL field?


One option then, might be to format the result with SQL using a CASE
WHEN THEN statement or ISNULL / IFNULL to set it to empty string

--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: How to output a NULL field?

am 27.08.2009 15:40:13 von Martin Scotta

--00151757674c092f0404721fb55f
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On Thu, Aug 27, 2009 at 9:37 AM, David Stoltz wrote:

> You're a genius - that works!!!!!
>
>
> -----Original Message-----
> From: Bastien Koert [mailto:phpster@gmail.com]
> Sent: Wednesday, August 26, 2009 2:02 PM
> To: Andrew Ballard
> Cc: Shawn McKenzie; php-general@lists.php.net; David Stoltz
> Subject: Re: [PHP] Re: How to output a NULL field?
>
>
> One option then, might be to format the result with SQL using a CASE
> WHEN THEN statement or ISNULL / IFNULL to set it to empty string
>
> --
>
> Bastien
>
> Cat, the other other white meat
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Let me do this simple question... is your Sql Server legal? Then use it.

If not, why don't you migrate to an open source alternative? there are a lot
of DB you can use, and if you use an open source alternative then it's
legal, that's mean you, or your client, do not have to pay for use it.

I'm not going to say *that* DB is better that *this* other, this is a matter
of taste.

--
Martin Scotta

--00151757674c092f0404721fb55f--

Special Characters in a String for Output

am 27.08.2009 15:56:03 von David Stoltz

I have:

$goalString =3D "

Goals Entered By =
".$mymanager."

On
".$when.":

".$mygoal."

";

Which outputs in this tag:

$goalString;
?>','normal','linear','mouse','out',1,1,'mouseout','yellow', false,'','',
0,0,'auto','auto','auto','auto')">....

But if there are double or single quotes in any of the $goalString, it
messes up the output.

I know this is a simple fix, but I'm not sure how to fix it since I'm
new to PHP...

I've tried addslashes, etc - but can't get it to work right...

Is there an easy way to escape ALL special characters that would cause
this output to fail?

Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Special Characters in a String for Output

am 27.08.2009 16:44:19 von Phpster

On Thu, Aug 27, 2009 at 9:56 AM, David Stoltz wrote:
> I have:
>
> $goalString = "

Goals Entered By ".$mymanager."

On
> ".$when.":

".$mygoal."

";
>
> Which outputs in this
tag:
>
>
....
>
> But if there are double or single quotes in any of the $goalString, it
> messes up the output.
>
> I know this is a simple fix, but I'm not sure how to fix it since I'm
> new to PHP...
>
> I've tried addslashes, etc - but can't get it to work right...
>
> Is there an easy way to escape ALL special characters that would cause
> this output to fail?
>
> Thanks!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


use htmlentities


--

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Date Comparison

am 28.08.2009 16:12:50 von David Stoltz

How to I ensure a variable date is not in the past, compared to the
current date? Here's how I'm trying, unsuccessfully:

$nextdate =3D "8/2/2009";

if(strtotime($nextdate)<=3Dgetdate()){

echo "Sorry, your next evaluation date cannot be in the past,
Click BACK to continue.";
exit;
=09
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date Comparison

am 28.08.2009 16:18:57 von Stut

2009/8/28 David Stoltz :
> How to I ensure a variable date is not in the past, compared to the
> current date? Here's how I'm trying, unsuccessfully:
>
> $nextdate =3D "8/2/2009";
>
> if(strtotime($nextdate)<=3Dgetdate()){
>
>        echo "Sorry, your next evaluation date cannot =
be in the past,
> Click BACK to continue.";
>        exit;
>
> }

RTFM.

The strtotime function will give you a timestamp, getdate will give
you an array, so your comparison is non-sensical. Use the time
function to get the current date/time as a timestamp.

-Stuart

--=20
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date Comparison

am 28.08.2009 17:12:23 von TedD

At 10:12 AM -0400 8/28/09, David Stoltz wrote:
>How to I ensure a variable date is not in the past, compared to the
>current date? Here's how I'm trying, unsuccessfully:
>
>$nextdate = "8/2/2009";
>
>if(strtotime($nextdate)<=getdate()){
>
> echo "Sorry, your next evaluation date cannot be in the past,
>Click BACK to continue.";
> exit;
>
>}

David:

Try to understand what strtotime() does and you'll get your answer.

Function returns the number of seconds from January 1, 1970 to the
date you enter. If the number of seconds are less than the current
date, then the entry is past.

Understand?

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date Comparison

am 28.08.2009 19:01:14 von David Stoltz

SGV5IFN0dWFydCAtIA0KDQpSVEZNIHlvdXJzZWxmLi4uLkkgZGlkIHJlYWQg aXQsIGFuZCBvYnZp
b3VzbHkgbWlzdW5kZXJzdG9vZC4uLg0KDQpJJ20gcmVhbGx5IHNvcnJ5IHRv IGJvdGhlciB5b3Uu
IEkgdGhvdWdodCB0aGF0IHdhcyB3aGF0IGEgbGlzdHNlcnYgbGlrZSB0aGlz IHdhcyBmb3IgLSB0
byBhc2sgcXVlc3Rpb25zLi4uDQoNCkknbGwgdHJ5IG5vdCB0byBhc2sgcXVl c3Rpb25zIEkgc2hv
dWxkIGtub3cgdGhlIGFuc3dlciB0byBuZXh0IHRpbWUuDQoNCg0KLS0tLS1P cmlnaW5hbCBNZXNz
YWdlLS0tLS0NCkZyb206IFN0dWFydCBbbWFpbHRvOnN0dXR0bGVAZ21haWwu Y29tXSANClNlbnQ6
IEZyaWRheSwgQXVndXN0IDI4LCAyMDA5IDEwOjE5IEFNDQpUbzogRGF2aWQg U3RvbHR6DQpDYzog
cGhwLWdlbmVyYWxAbGlzdHMucGhwLm5ldA0KU3ViamVjdDogUmU6IFtQSFBd IERhdGUgQ29tcGFy
aXNvbg0KDQoyMDA5LzgvMjggRGF2aWQgU3RvbHR6IDxEc3RvbHR6QHNoaC5v cmc+Og0KPiBIb3cg
dG8gSSBlbnN1cmUgYSB2YXJpYWJsZSBkYXRlIGlzIG5vdCBpbiB0aGUgcGFz dCwgY29tcGFyZWQg
dG8gdGhlDQo+IGN1cnJlbnQgZGF0ZT8gSGVyZSdzIGhvdyBJJ20gdHJ5aW5n LCB1bnN1Y2Nlc3Nm
dWxseToNCj4NCj4gJG5leHRkYXRlID0gIjgvMi8yMDA5IjsNCj4NCj4gaWYo c3RydG90aW1lKCRu
ZXh0ZGF0ZSk8PWdldGRhdGUoKSl7DQo+DQo+IMKgIMKgIMKgIMKgZWNobyAi U29ycnksIHlvdXIg
bmV4dCBldmFsdWF0aW9uIGRhdGUgY2Fubm90IGJlIGluIHRoZSBwYXN0LA0K PiBDbGljayBCQUNL
IHRvIGNvbnRpbnVlLiI7DQo+IMKgIMKgIMKgIMKgZXhpdDsNCj4NCj4gfQ0K DQpSVEZNLg0KDQpU
aGUgc3RydG90aW1lIGZ1bmN0aW9uIHdpbGwgZ2l2ZSB5b3UgYSB0aW1lc3Rh bXAsIGdldGRhdGUg
d2lsbCBnaXZlDQp5b3UgYW4gYXJyYXksIHNvIHlvdXIgY29tcGFyaXNvbiBp cyBub24tc2Vuc2lj
YWwuIFVzZSB0aGUgdGltZQ0KZnVuY3Rpb24gdG8gZ2V0IHRoZSBjdXJyZW50 IGRhdGUvdGltZSBh
cyBhIHRpbWVzdGFtcC4NCg0KLVN0dWFydA0KDQotLSANCmh0dHA6Ly9zdHV0 Lm5ldC8NCg==

RE: Date Comparison

am 29.08.2009 15:44:58 von TedD

At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>Hey Stuart -
>
>RTFM yourself....I did read it, and obviously misunderstood...
>
>I'm really sorry to bother you. I thought that was what a listserv
>like this was for - to ask questions...
>
>I'll try not to ask questions I should know the answer to next time.

Whoa dude!

You just received advice from a brilliant man and you are bitching about it?!?

Look child, you are being told what you should do by a professional
who is donating his time freely to help you. Just how did you not
understand that?

So, just do what he advised and say "Thank you sir, may I have another?"

I've posted some dumb-ass questions before, but only after I took the
time to research the question myself. And when someone took the time
to straighten me out and help, I appreciated it.

Hopefully next time you'll read the manual and take the time to
understand what you read -- it would cut down on post that
demonstrate just how ignorant and thankless you are at this.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Date +30 comparison

am 01.09.2009 18:19:07 von David Stoltz

I'm really struggling with dates in PHP. (Yes, I tried reading the
manual)...

Can someone provide code that does this:

Takes current date, assigns it to a variable (let's say $today)
Then adds 30 days to $today variable
Takes a string ($nexteval) like '8/26/2009' and compare it to $today.

The variable $nexteval must be greater than $today (which is today + 30
days) or a message is echoed.

I'm finding this difficult to do, but I'm coming from an ASP background.

Any help appreciated.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 18:43:29 von Ashley Sheridan

On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
>
> Can someone provide code that does this:
>
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>
> The variable $nexteval must be greater than $today (which is today + 30
> days) or a message is echoed.
>
> I'm finding this difficult to do, but I'm coming from an ASP background.
>
> Any help appreciated.
>

PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 18:55:24 von Dan Shirah

--000e0cd6a8084aacc8047287041c
Content-Type: text/plain; charset=ISO-8859-1

>
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
>
> Can someone provide code that does this:
>
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>
> The variable $nexteval must be greater than $today (which is today + 30
> days) or a message is echoed.
>
> I'm finding this difficult to do, but I'm coming from an ASP background.
>
> Any help appreciated.
>
David,

Look up date() and mktime() in the manual.

To get today's date is easy: date('m/d/Y');

But when wanting to add days/months/years to a date, you need to use
mktime()

mktime() breaks apart a date into hours/minutes/seconds/months/days/years.

Therefore I always break up my date into these types fo sections.

$month = date('m');
$day = date('d');
$year = date('Y');

Now that I have them seperated I create a variable $future_date and assign
it the value I want. In your case, 30 days in the future.

$future_date = mktime(0,0,0,date($month),date($day)+30,date($year));

Now I put it back into a date format.

$future_date = date('m/d/Y',$future_date);

echo $future_date;

Today is September 1st and the value of $future_date is October 1st because
there are 30 days in Spetember.

Now you can compare your dates.

if ($nexteval > $future_date) {
echo "This date has already passed";
} else {
*do some processing*
}

Hope that helps.

Dan

--000e0cd6a8084aacc8047287041c--

Re: Date +30 comparison

am 01.09.2009 19:00:14 von kranthi

i prefer http://in3.php.net/strtotime it supports loads of other
formats as well (including +30 days and 8/26/2009)
above all it returns unix time stamp which can be used directly with date().

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 19:27:26 von TedD

At 5:43 PM +0100 9/1/09, Ashley Sheridan wrote:
>On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
>> I'm really struggling with dates in PHP. (Yes, I tried reading the
>> manual)...
>>
>> Can someone provide code that does this:
>>
>> Takes current date, assigns it to a variable (let's say $today)
>> Then adds 30 days to $today variable
>> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>>
> > The variable $nexteval must be greater than $today (which is today + 30
>> days) or a message is echoed.
>>
>> I'm finding this difficult to do, but I'm coming from an ASP background.
> >
> > Any help appreciated.
>>
>
>PHP (like all languages I know) treats dates as numbers; and PHP
>specifically uses seconds since January 1st 1970 (other languages
>sometimes have different start points and can measure in milliseconds
>instead). With this in mind, you can compare dates directly as you would
>an integer, and the later date will be the higher value.
>
>To add 30 days to a given date, you could use the date_add function
>(http://uk2.php.net/manual/en/datetime.add.php ) which has various
>formats you can use to add different time units.
>
>Lastly, to turn a date like 8/26/2009, I would probably try to break it
>down into it's component parts (maybe using explode('/', $string_date) )
>and then using those values as arguments in a mktime() function. PHP
>should automatically treat the values as integers if they are strings,
>because like ASP, it uses loose typing on variables.

David :

First get the date to seconds, like so:

$today_date = '8/26/2009';

$next_date = strtotime($today_date) + (86400 * 30);

OR

$next_date = strtotime('+30 days', strtotime($today_date));

Then take the seconds back to a date, like so:

$the_date = date('m/d/Y', $next_date);

Here's the example:

http://www.webbytedd.com/bbbb/future-date/

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date +30 comparison

am 01.09.2009 19:28:35 von David Stoltz

Ok, this is how I finally managed to get it to work - I'm sure there are
other ways, but this works:

//Check to make sure the next eval date is more than 30 days away

$d1 =3D date('Y-m-d', strtotime($todays_date . '+30 day'));
$d2 =3D date('Y-m-d', strtotime($nextdate));

if($d1>$d2){

echo "Sorry, your next evaluation date must be at least 30 days
away, Click BACK to continue.";
exit;
=09
}


-----Original Message-----
From: Ashley Sheridan [mailto:ash@ashleysheridan.co.uk]=20
Sent: Tuesday, September 01, 2009 12:43 PM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Date +30 comparison

On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
>=20
> Can someone provide code that does this:
>=20
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>=20
> The variable $nexteval must be greater than $today (which is today +
30
> days) or a message is echoed.
>=20
> I'm finding this difficult to do, but I'm coming from an ASP
background.
>=20
> Any help appreciated.
>=20

PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 19:30:33 von Shawn McKenzie

David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
>
> Can someone provide code that does this:
>
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>
> The variable $nexteval must be greater than $today (which is today + 30
> days) or a message is echoed.
>
> I'm finding this difficult to do, but I'm coming from an ASP background.
>
> Any help appreciated.

Look at the date/time functions, they are very feature rich:

$today = time();
$nexteval = strtotime('+30 days', $today);

if ($today > $nexteval) {
echo 'Message';
}

--
Thanks!
-Shawn
http://www.spidean.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date +30 comparison

am 01.09.2009 19:49:38 von TedD

At 1:28 PM -0400 9/1/09, David Stoltz wrote:
>Ok, this is how I finally managed to get it to work - I'm sure there are
>other ways, but this works:
>
>//Check to make sure the next eval date is more than 30 days away
>
>$d1 = date('Y-m-d', strtotime($todays_date . '+30 day'));
>$d2 = date('Y-m-d', strtotime($nextdate));
>
>if($d1>$d2){
>
> echo "Sorry, your next evaluation date must be at least 30 days
>away, Click BACK to continue.";
> exit;

You got it.

Just transform any date to seconds and then compare those seconds to
other seconds (taken from other dates) and evaluate. Dead simple.

Also note that the strtotime() and date() combination provides some
very nice features like keeping track of the resultant date. You
don't have to worry about leap years, or months having 28-31 days, or
anything like that -- it's all taken care of for you, pretty neat huh?

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 20:47:43 von Andrew Ballard

On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:
> First get the date to seconds, like so:
>
> $today_date =3D '8/26/2009';
>
> $next_date =3D strtotime($today_date) + (86400 * 30);
>

No. Due to Daylight Saving Time, many time zones have two days each
year when the number of seconds in a day is not 86400.

> OR
>
> $next_date  =3D strtotime('+30 days', strtotime($today_date));
>
> Then take the seconds back to a date, like so:
>
> $the_date =3D date('m/d/Y', $next_date);

Yes.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 21:12:08 von Paul M Foster

On Tue, Sep 01, 2009 at 02:47:43PM -0400, Andrew Ballard wrote:

> On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:
> > First get the date to seconds, like so:
> >
> > $today_date = '8/26/2009';
> >
> > $next_date = strtotime($today_date) + (86400 * 30);
> >
>
> No. Due to Daylight Saving Time, many time zones have two days each
> year when the number of seconds in a day is not 86400.

This and the "2038" bug are reasons to do this type of calculation with
Julian days, as opposed to seconds.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date +30 comparison

am 01.09.2009 22:51:38 von TedD

At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
>On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:
>> First get the date to seconds, like so:
>>
>> $today_date = '8/26/2009';
>>
>> $next_date = strtotime($today_date) + (86400 * 30);
>>
>
>No. Due to Daylight Saving Time, many time zones have two days each
>year when the number of seconds in a day is not 86400.
>

Arrggg.

But good to know.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date +30 comparison

am 02.09.2009 17:06:12 von M.Ford

> -----Original Message-----
> From: tedd [mailto:tedd.sperling@gmail.com]
> Sent: 01 September 2009 21:52
>=20
> At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
> >On Tue, Sep 1, 2009 at 1:27 PM, tedd
> wrote:
> >> First get the date to seconds, like so:
> >>
> >> $today_date =3D '8/26/2009';
> >>
> >> $next_date =3D strtotime($today_date) + (86400 * 30);
> >>
> >
> >No. Due to Daylight Saving Time, many time zones have two days each
> >year when the number of seconds in a day is not 86400.
> >
>=20
> Arrggg.
>=20
> But good to know.

And if you absolutely insist on doing it this way, make sure you start in t=
he middle of the day -- if your base time is 12:00 noon (which is what I al=
ways use in this situation), the furthest it can go because of DST is 11:00=
or 13:00, which won't screw you up if all you're interested in is the date=
.. ;)


Cheers!

Mike
--=20
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,=20
Woodhouse Lane, LEEDS,=A0 LS1 3HE,=A0 United Kingdom=20
Email: m.ford@leedsmet.ac.uk=20
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to http:=
//disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date +30 comparison

am 02.09.2009 20:59:15 von TedD

At 4:06 PM +0100 9/2/09, Ford, Mike wrote:
> > -----Original Message-----
>> From: tedd [mailto:tedd.sperling@gmail.com]
>> Sent: 01 September 2009 21:52
>>
>> At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
>> >On Tue, Sep 1, 2009 at 1:27 PM, tedd
>> wrote:
>> >> First get the date to seconds, like so:
>> >>
>> >> $today_date = '8/26/2009';
>> >>
>> >> $next_date = strtotime($today_date) + (86400 * 30);
>> >>
>> >
>> >No. Due to Daylight Saving Time, many time zones have two days each
>> >year when the number of seconds in a day is not 86400.
>> >
>>
>> Arrggg.
>>
>> But good to know.
>
>And if you absolutely insist on doing it this way, make sure you
>start in the middle of the day -- if your base time is 12:00 noon
>(which is what I always use in this situation), the furthest it can
>go because of DST is 11:00 or 13:00, which won't screw you up if all
>you're interested in is the date. ;)
>
>
>Cheers!
>
>Mike

Another good thing to know.

Thanks,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date Comparison

am 03.09.2009 10:01:14 von J DeBord

--00c09ffb568ec954910472a7ca91
Content-Type: text/plain; charset=UTF-8

Telling someone RTFM is just rude and mean. Manipulating dates and times can
be confusing for beginners and experienced people alike. I would suggest
that when a question asked here causes you to respond with RTFM, don't
respond at all. Save yourself the time and trouble and save the person
asking the question the grief of being insulted. And Tedd your condescending
response caused me to lose respect for you. I'm sure the OP would have been
more than thankful to receive the same response without the RTFM. I'll read
any response to this, but I won't have anything more to say. This list has
been polluted enough lately with nonsense. Incredible.


On Sat, Aug 29, 2009 at 3:44 PM, tedd wrote:

> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>
>> Hey Stuart -
>>
>> RTFM yourself....I did read it, and obviously misunderstood...
>>
>> I'm really sorry to bother you. I thought that was what a listserv like
>> this was for - to ask questions...
>>
>> I'll try not to ask questions I should know the answer to next time.
>>
>
> Whoa dude!
>
> You just received advice from a brilliant man and you are bitching about
> it?!?
>
> Look child, you are being told what you should do by a professional who is
> donating his time freely to help you. Just how did you not understand that?
>
> So, just do what he advised and say "Thank you sir, may I have another?"
>
> I've posted some dumb-ass questions before, but only after I took the time
> to research the question myself. And when someone took the time to
> straighten me out and help, I appreciated it.
>
> Hopefully next time you'll read the manual and take the time to understand
> what you read -- it would cut down on post that demonstrate just how
> ignorant and thankless you are at this.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--00c09ffb568ec954910472a7ca91--

Re: Date Comparison

am 03.09.2009 11:20:49 von Stut

2009/9/3 J DeBord :
> Telling someone RTFM is just rude and mean. Manipulating dates and times =
can
> be confusing for beginners and experienced people alike. I would suggest
> that when a question asked here causes you to respond with RTFM, don't
> respond at all. Save yourself the time and trouble and save the person
> asking the question the grief of being insulted. And Tedd your condescend=
ing
> response caused me to lose respect for you. I'm sure the OP would have be=
en
> more than thankful to receive the same response without the RTFM. I'll re=
ad
> any response to this, but I won't have anything more to say. This list ha=
s
> been polluted enough lately with nonsense. Incredible.

You're entitled to your opinion as much as I am, and my opinion is
that not making it clear to people that the answer to their question
is plainly obvious in the manual is just as rude if not more so than
suggesting they RTFM.

I make a point to never just say RTFM but to also answer the question
at the same time, but IMHO not telling people how fundamental their
question was does not help them in the long run. At the end of the day
it just encourages them to continue to rely on this list rather than
learning how to find the answer themselves and to only use this list
as a last resort.

I make no apology for my attitude towards this type of question, and
if you don't like it you can stick it where the sun don't shine.

-Stuart

--=20
http://stut.net/

> On Sat, Aug 29, 2009 at 3:44 PM, tedd wrote:
>
>> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>>
>>> Hey Stuart -
>>>
>>> RTFM yourself....I did read it, and obviously misunderstood...
>>>
>>> I'm really sorry to bother you. I thought that was what a listserv like
>>> this was for - to ask questions...
>>>
>>> I'll try not to ask questions I should know the answer to next time.
>>>
>>
>> Whoa dude!
>>
>> You just received advice from a brilliant man and you are bitching about
>> it?!?
>>
>> Look child, you are being told what you should do by a professional who =
is
>> donating his time freely to help you. Just how did you not understand th=
at?
>>
>> So, just do what he advised and say "Thank you sir, may I have another?"
>>
>> I've posted some dumb-ass questions before, but only after I took the ti=
me
>> to research the question myself. And when someone took the time to
>> straighten me out and help, I appreciated it.
>>
>> Hopefully next time you'll read the manual and take the time to understa=
nd
>> what you read -- it would cut down on post that demonstrate just how
>> ignorant and thankless you are at this.
>>
>> Cheers,
>>
>> tedd
>>
>> --
>> -------
>> http://sperling.com  http://ancientstones.com  http://earthsto=
nes.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date Comparison

am 03.09.2009 17:12:10 von Paul M Foster

On Thu, Sep 03, 2009 at 10:20:49AM +0100, Stuart wrote:

> 2009/9/3 J DeBord :
> > Telling someone RTFM is just rude and mean. Manipulating dates and times can
> > be confusing for beginners and experienced people alike. I would suggest
> > that when a question asked here causes you to respond with RTFM, don't
> > respond at all. Save yourself the time and trouble and save the person
> > asking the question the grief of being insulted. And Tedd your condescending
> > response caused me to lose respect for you. I'm sure the OP would have been
> > more than thankful to receive the same response without the RTFM. I'll read
> > any response to this, but I won't have anything more to say. This list has
> > been polluted enough lately with nonsense. Incredible.
>
> You're entitled to your opinion as much as I am, and my opinion is
> that not making it clear to people that the answer to their question
> is plainly obvious in the manual is just as rude if not more so than
> suggesting they RTFM.
>
> I make a point to never just say RTFM but to also answer the question
> at the same time, but IMHO not telling people how fundamental their
> question was does not help them in the long run. At the end of the day
> it just encourages them to continue to rely on this list rather than
> learning how to find the answer themselves and to only use this list
> as a last resort.
>
> I make no apology for my attitude towards this type of question, and
> if you don't like it you can stick it where the sun don't shine.

+1

I can't argue with this approach. If you're going to point the poster to
the manual and *then* explain, that's the ideal way to do this. Now it
could be argued that you could say, "Please refer to
http://php.net/manual/en/whatever.php for more info." Or you could say,
"RTFM". The former is more polite, but the latter will suffice. Both
mean the same thing; one is simply more terse.

Also stipulated that one should research a question as much as possible
before posting to this list. We're not tutors; more like professional
side-checkers.

(Please don't take this the wrong way, newbies. You're welcome to ask
questions here. Just do whatever research you can first, and follow our
advice afterward, to RTFM.)

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date Comparison

am 03.09.2009 21:40:02 von TedD

At 10:01 AM +0200 9/3/09, J DeBord wrote:
>Telling someone RTFM is just rude and mean.

And not taking the time to research your question before posting is
what, thoughtful and kind?

The phrase RTFM is something I don't like to tell people, and from
what I remember, I have never said that to anyone. However I can
understand where one could read a person's question and deduce that
they did NO research for themselves. Instead, they posted their
question for others to do their research for them because they were
too lazy to do it themselves. No matter how you cut that, that's
lame. So, I certainly don't blame anyone for telling such a person to
RTFM.

> I would suggest
>that when a question asked here causes you to respond with RTFM, don't
>respond at all. Save yourself the time and trouble and save the person
>asking the question the grief of being insulted.

Well that's your prerogative to do as you want. But it's a bit
arrogant of you to tell others how to conduct themselves on this
list, don't you think? Who made you list monitor?


>And Tedd your condescending
>response caused me to lose respect for you.

No offense, but let me make this perfectly clear -- I don't give a
rat's ass what you think about me. From my perspective, you could win
the lottery or die tomorrow, it makes no difference to me either way.

I'm not here to win/lose your respect. I'm here to help those who ask
honest questions. I, like many others, simply donate our time freely
without any benefit whatsoever. If you have problems with that, then
you probably have bigger problems elsewhere.


>I'm sure the OP would have been
>more than thankful to receive the same response without the RTFM. I'll read
>any response to this, but I won't have anything more to say. This list has
>been polluted enough lately with nonsense. Incredible.

What's Incredible is how people can post to this list thinking that
they have some right to post whatever they want and expect others to
comment as they want. And, if they don't get what they want, then
they whine about the list being rude and mean. That's Incredible.

My advice, if you have problems with this list, get over it! There's
much more in this world to get upset about rather than what happens
on this list.

tedd

---

>
>
>On Sat, Aug 29, 2009 at 3:44 PM, tedd wrote:
>
>> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>>
>>> Hey Stuart -
>>>
>>> RTFM yourself....I did read it, and obviously misunderstood...
>>>
>>> I'm really sorry to bother you. I thought that was what a listserv like
>>> this was for - to ask questions...
>>>
>>> I'll try not to ask questions I should know the answer to next time.
>>>
>>
>> Whoa dude!
>>
>> You just received advice from a brilliant man and you are bitching about
>> it?!?
>>
>> Look child, you are being told what you should do by a professional who is
>> donating his time freely to help you. Just how did you not understand that?
>>
>> So, just do what he advised and say "Thank you sir, may I have another?"
>>
>> I've posted some dumb-ass questions before, but only after I took the time
>> to research the question myself. And when someone took the time to
>> straighten me out and help, I appreciated it.
>>
>> Hopefully next time you'll read the manual and take the time to understand
>> what you read -- it would cut down on post that demonstrate just how
>> ignorant and thankless you are at this.
>>
>> Cheers,
>>
>> tedd
>>
>> --
>> -------
>> http://sperling.com http://ancientstones.com http://earthstones.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php