RE: [PHP] How to output a NULL field?

2009-08-26 Thread David Stoltz
Paul,

This all started because when I try this:

?php echo $rs-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 MySQLnot
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:pa...@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: ?php echo $q4;?
 
 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



Re: [PHP] How to output a NULL field?

2009-08-26 Thread hack988 hack988
use is_null() check it

2009/8/26 David Stoltz dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread David Stoltz
I tried that -it's in the first part of my message


-Original Message-
From: hack988 hack988 [mailto:hack...@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 dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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 dsto...@shh.org:
 I tried that -it's in the first part of my message


 -Original Message-
 From: hack988 hack988 [mailto:hack...@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 dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread TG
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 dsto...@shh.org
To: Paul M Foster pa...@quillandmouse.com, php-general@lists.php.net
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:
 
 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?
  
  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: [PHP] How to output a NULL field?

2009-08-26 Thread Stuart
2009/8/26 David Stoltz dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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 = $rs-Fields(22);
var_dump($var);

...and tell us what you get.

-Stuart

-- 
http://stut.net/

 -Original Message-
 From: Paul M Foster [mailto:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread David Stoltz
This:
$var = $rs-Fields(22);
var_dump($var);

Produces this:
object(variant)#3 (0) { }

-Original Message-
From: Stuart [mailto:stut...@gmail.com] 
Sent: Wednesday, August 26, 2009 8:47 AM
To: David Stoltz
Cc: Paul M Foster; php-general@lists.php.net
Subject: Re: [PHP] How to output a NULL field?

2009/8/26 David Stoltz dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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 = $rs-Fields(22);
var_dump($var);

...and tell us what you get.

-Stuart

-- 
http://stut.net/

 -Original Message-
 From: Paul M Foster [mailto:pa...@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: ?php echo $q4;?

 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




Re: [PHP] How to output a NULL field?

2009-08-26 Thread 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
--
?php
if(!defined('IN_WEB')) {
exit('Access Denied');
}
ini_set('mssql.datetimeconvert',0);//php4.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,$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 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{
   

RE: [PHP] How to output a NULL field?

2009-08-26 Thread David Stoltz
Sorry - I don't know what you mean by DB class?

I'm using Microsoft SQL 2000with this code:

?php
//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=;UID=xxx;PWD=;DATABASE=; 
$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:hack...@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 dsto...@shh.org:
 I tried that -it's in the first part of my message


 -Original Message-
 From: hack988 hack988 [mailto:hack...@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 dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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 dsto...@shh.org:
 Sorry - I don't know what you mean by DB class?

 I'm using Microsoft SQL 2000with this code:

 ?php
 //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=;UID=xxx;PWD=;DATABASE=;
 $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:hack...@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 dsto...@shh.org:
 I tried that -it's in the first part of my message


 -Original Message-
 From: hack988 hack988 [mailto:hack...@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 dsto...@shh.org:
 Paul,

 This all started because when I try this:

 ?php echo $rs-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 MySQLnot
 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:pa...@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: ?php echo $q4;?

 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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 dsto...@shh.org:
  Sorry - I don't know what you mean by DB class?
 
  I'm using Microsoft SQL 2000with this code:
 
  ?php
  //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=;UID=xxx;PWD=;DATABASE=;
  $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:hack...@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 dsto...@shh.org:
  I tried that -it's in the first part of my message
 
 
  -Original Message-
  From: hack988 hack988 [mailto:hack...@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 dsto...@shh.org:
  Paul,
 
  This all started because when I try this:
 
  ?php echo $rs-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 MySQLnot
  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:pa...@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: ?php echo $q4;?
 
  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: [PHP] How to output a NULL field?

2009-08-26 Thread David Stoltz
Wow - thanks for the code, but it's over my head at this point.

I'm a PHP newbieI 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:hack...@dev.htwap.com] 
Sent: Wednesday, August 26, 2009 10:13 AM
To: a...@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
--
?php
if(!defined('IN_WEB')) {
exit('Access Denied');
}
ini_set('mssql.datetimeconvert',0);//php4.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,$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 connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect =
0,$auto_conn=0 ,$newlink=false

RE: [PHP] How to output a NULL field?

2009-08-26 Thread 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.
 
 I'm a PHP newbieI 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:hack...@dev.htwap.com] 
 Sent: Wednesday, August 26, 2009 10:13 AM
 To: a...@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
 --
 ?php
 if(!defined('IN_WEB')) {
   exit('Access Denied');
 }
 ini_set('mssql.datetimeconvert',0);//php4.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,$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 connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect =
 0,$auto_conn=0 ,$newlink=false

Re: [PHP] How to output a NULL field?

2009-08-26 Thread Andrew Ballard
On Wed, Aug 26, 2009 at 10:52 AM, Ashley
Sheridana...@ashleysheridan.co.uk 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: [PHP] How to output a NULL field?

2009-08-26 Thread Andrew Ballard
On Wed, Aug 26, 2009 at 9:51 AM, David Stoltzdsto...@shh.org wrote:
 Sorry - I don't know what you mean by DB class?

 I'm using Microsoft SQL 2000with this code:

 ?php
 //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=;UID=xxx;PWD=;DATABASE=;
 $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



Re: [PHP] How to output a NULL field?

2009-08-26 Thread hack988 hack988
Com function is just for Windows,I don't kown why some body like use it.:(

2009/8/27 Andrew Ballard aball...@gmail.com:
 On Wed, Aug 26, 2009 at 9:51 AM, David Stoltzdsto...@shh.org wrote:
 Sorry - I don't know what you mean by DB class?

 I'm using Microsoft SQL 2000with this code:

 ?php
 //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=;UID=xxx;PWD=;DATABASE=;
 $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



Re: [PHP] How to output a NULL field?

2009-08-26 Thread Andrew Ballard
On Wed, Aug 26, 2009 at 12:13 PM, Andrew Ballardaball...@gmail.com wrote:
 On Wed, Aug 26, 2009 at 9:51 AM, David Stoltzdsto...@shh.org wrote:
 Sorry - I don't know what you mean by DB class?

 I'm using Microsoft SQL 2000with this code:

 ?php
 //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=;UID=xxx;PWD=;DATABASE=;
 $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:


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: [PHP] How to output a NULL field?

2009-08-26 Thread Andrew Ballard
On Wed, Aug 26, 2009 at 12:06 PM, hack988 hack988hack...@dev.htwap.com 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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: [PHP] How to output a NULL field?

2009-08-26 Thread 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 = 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:hack...@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 aball...@gmail.com:
 On Wed, Aug 26, 2009 at 9:51 AM, David Stoltzdsto...@shh.org wrote:
 Sorry - I don't know what you mean by DB class?

 I'm using Microsoft SQL 2000with this code:

 ?php
 //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=;UID=xxx;PWD=;DATABASE=;
 $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



Re: [PHP] How to output a NULL field?

2009-08-26 Thread 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



[PHP] How to output a NULL field?

2009-08-26 Thread 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:pa...@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


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



Re: [PHP] How to output a NULL field?

2009-08-26 Thread 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:pa...@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: [PHP] How to output a NULL field?

2009-08-26 Thread 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: [PHP] How to output a NULL field?

2009-08-26 Thread Phpster





On Aug 26, 2009, at 12:31 PM, David Stoltz dsto...@shh.org 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:hack...@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 aball...@gmail.com:

On Wed, Aug 26, 2009 at 9:51 AM, David Stoltzdsto...@shh.org wrote:

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

I'm using Microsoft SQL 2000with this code:

?php
//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=;UID=xxx;PWD=;DATABASE=;

$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



[PHP] How to output a NULL field?

2009-08-25 Thread David Stoltz
$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: ?php echo $q4;?

What am I doing wrong?

Thanks!

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



Re: [PHP] How to output a NULL field?

2009-08-25 Thread Bastien Koert
On Tue, Aug 25, 2009 at 2:00 PM, David Stoltzdsto...@shh.org 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: ?php echo $q4;?

 What am I doing wrong?

 Thanks!

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




$q4 =  '' . $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



RE: [PHP] How to output a NULL field?

2009-08-25 Thread David Stoltz
if(empty($rs-Fields(22))){
$q4 = '';
}else{
$q4 = ''.$rs-Fields(22);
}  

Still produces errors, whether using empty or is_nullwith single 
quotes

???

-Original Message-
From: Bastien Koert [mailto:phps...@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 Stoltzdsto...@shh.org 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: ?php echo $q4;?

 What am I doing wrong?

 Thanks!

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




$q4 =  '' . $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



Re: [PHP] How to output a NULL field?

2009-08-25 Thread Lars Torben Wilson
2009/8/25 David Stoltz dsto...@shh.org:
 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

        $q4 = '';
 }else{
        $q4 = ''.$rs-Fields(22);
 }

 Still produces errors, whether using empty or is_nullwith single 
 quotes

 ???

 -Original Message-
 From: Bastien Koert [mailto:phps...@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 Stoltzdsto...@shh.org 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: ?php echo $q4;?

 What am I doing wrong?

 Thanks!

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




 $q4 =  '' . $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: [PHP] How to output a NULL field?

2009-08-25 Thread 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: ?php echo $q4;?
 
 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