Re: [PHP-DB] Where does the mysqli extension find the default connection charset?

2007-05-03 Thread Jean-Noël Rivasseau

Hello and thanks for your help,

However, my question was: *how* is it package dependent? You said that it
uses libmysql. In this case, which file controls the configuration of
libmysql? Or is it at compilation time that the choice is made?

I know that to be of the safe side, I should explicitly set the character
set.

Jean-Noel



On 5/2/07, Georg Richter [EMAIL PROTECTED] wrote:


Jean-Noël Rivasseau wrote:
 Hello there,

 I'd like to know which configuration file or setting is used by PHP
mysqli
 extension to know the default charset connection to the database.

mysqli (and also mysql) extension uses the default character set for
libmysql  This can be package dependend: Several distros deliver utf8 as
default, others latin1.

To be on the safe side, you should call mysqli_set_charset($link,
utf8/latin1/whatever) to set the character set for each connection.

/Georg
--
Georg Richter, Development Manager - Connectors  Client Connectivity
MySQL GmbH, Radlkoferstr. 2, D-81373 München, www.mysql.com
Geschäftsführer: Hans von Bell, Kaj Arnö - HRB München 162140



[PHP-DB] weird comparsion

2007-05-03 Thread OKi98

Hello,

Why does anything compared to 0 return true?

I know it might seem to be a bit off-topic, but for me it is important 
for detecting if NULL value in table has been changed (for example NULL 
is changed to 0).


if (foo==0) echo(foo equals to 0);

OKi98

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



Re: [PHP-DB] weird comparsion

2007-05-03 Thread Mike van Hoof

http://nl3.php.net/manual/en/language.operators.comparison.php

try using === (3x =) for comparison

- Mike

OKi98 schreef:

Hello,

Why does anything compared to 0 return true?

I know it might seem to be a bit off-topic, but for me it is important 
for detecting if NULL value in table has been changed (for example 
NULL is changed to 0).


if (foo==0) echo(foo equals to 0);

OKi98



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



Re: [PHP-DB] weird comparsion

2007-05-03 Thread Aleksandar Vojnovic

try comparing the type:

if(0 === 0)echo 'Its not equal';
if(0 === 0)echo 'Its equal';



OKi98 wrote:

Hello,

Why does anything compared to 0 return true?

I know it might seem to be a bit off-topic, but for me it is important 
for detecting if NULL value in table has been changed (for example 
NULL is changed to 0).


if (foo==0) echo(foo equals to 0);

OKi98



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



Re: [PHP-DB] weird comparsion

2007-05-03 Thread OKi98

Mike van Hoof wrote:


http://nl3.php.net/manual/en/language.operators.comparison.php

try using === (3x =) for comparison

- Mike

OKi98 schreef:


Hello,

Why does anything compared to 0 return true?

I know it might seem to be a bit off-topic, but for me it is 
important for detecting if NULL value in table has been changed (for 
example NULL is changed to 0).


if (foo==0) echo(foo equals to 0);

OKi98




__ Informace od NOD32 2235 (20070502) __

Tato zprava byla proverena antivirovym systemem NOD32.
http://www.nod32.cz



I know about identity operator (===) but with == operator 0 is false and 
foo is true, try this:


$foo=0;
$bar=bar;
if ($foo) echo($foo is true, );
   else echo($foo is false, );
if ($bar) echo($bar is true, );
   else echo($bar is false, );
if ($foo==$bar) echo($foo==$bar);

returns 0 is false, bar is true, 0==$bar

OKi98

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



RE: [PHP-DB] weird comparsion

2007-05-03 Thread Ford, Mike
On 03 May 2007 12:30, OKi98 wrote:

 I know about identity operator (===) but with == operator 0 is false
 and foo is true

No, that's not correct.

  , try this:
 
 $foo=0;
 $bar=bar;
 if ($foo) echo($foo is true, );
 else echo($foo is false, );
 if ($bar) echo($bar is true, );
 else echo($bar is false, );
 if ($foo==$bar) echo($foo==$bar);
 
 returns 0 is false, bar is true, 0==$bar

That's because you've got loads of implicit type conversions going on there, so 
you're not comparing like with like.

For  if ($foo) ... and if ($bar) ...:

within the context of the if(), both $foo and $bar are implicitly converted to 
Boolean:
  - (bool)0 is FALSE
  - (bool)any non-empty() string is TRUE


On the other hand, for  if ($foo==$bar) ...:

in the context of the == comparison, $bar is converted to a number, and any 
string not beginning with a numeric character converts to numeric zero -- so 
you get a comparison of zero with zero, which is, of course, TRUE!

Or, in other words, (bool)$foo!==(bool)$bar, BUT (int)$foo===(int)$bar


It's exactly when you *don't* want this kind of automatic type-conversion 
shenanigans going on that you should use the === operator to make your intent 
entirely clear -- otherwise you have to be extremely aware of the context in 
which you are evaluating your variables in order to avoid hidden surprises like 
this.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730  Fax:  +44 113 812 3211 


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


[PHP-DB] PDOStatement and fetchAll()

2007-05-03 Thread James McLean

Howdy,

I'm working with PDOStatement-fetchAll() and I need it to return the
Object I specify. I've got it working with individual rows and
PDOStatement-fetchObject(), i'm able to tell it what class to load
the variables into with this function and if I read correctly I should
also be able to do this with fetchAll() also.

The http://au.php.net/manual/en/function.PDOStatement-fetchAll.php
page says I should be able to use the $fetch_style outlined on the
fetch() page, but its not very clear hot to specify which class to
load.

For example, this code:
return $queryData-fetchObject(get_class($this));
does exactly what i want it to, puts the variables into the class I
specify so I can handle the data with custom methods..

I need to do the same with a fetchAll. I have it returning with an
anonymous object (called stdClass, the default) but would like to know
how to specify the object to call as above, as I need the flexibility
of custom classes with these result sets also.

I've experimented a little with the fetchAll() method, for example:
return $queryData-fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE);

and
return $queryData-fetchAll(PDO::FETCH_CLASS|get_class($this));

but both still only return the stdClass object..

Can someone explain how to do this with fetchAll() a little more clearly?

Cheers,

James

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



Re: [PHP-DB] weird comparsion

2007-05-03 Thread OKi98

Ford, Mike wrote:


On 03 May 2007 12:30, OKi98 wrote:

 


I know about identity operator (===) but with == operator 0 is false
and foo is true
   



No, that's not correct.

 , try this:
 


$foo=0;
$bar=bar;
if ($foo) echo($foo is true, );
   else echo($foo is false, );
if ($bar) echo($bar is true, );
   else echo($bar is false, );
if ($foo==$bar) echo($foo==$bar);

returns 0 is false, bar is true, 0==$bar
   



That's because you've got loads of implicit type conversions going on there, so 
you're not comparing like with like.

For  if ($foo) ... and if ($bar) ...:

within the context of the if(), both $foo and $bar are implicitly converted to 
Boolean:
 - (bool)0 is FALSE
 - (bool)any non-empty() string is TRUE


On the other hand, for  if ($foo==$bar) ...:

in the context of the == comparison, $bar is converted to a number, and any 
string not beginning with a numeric character converts to numeric zero -- so 
you get a comparison of zero with zero, which is, of course, TRUE!
 

oh I didnt know that, I thought the number will be converted into a 
string. Thanks alot.


I have one more question but I ask in separate thread :)

Oki98

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



[PHP-DB] variable with NULL value

2007-05-03 Thread OKi98

Hi,

one more question.

Why the variable, that contains NULL value appears to be not set. When 
you try to echo it the php does not produce warning about using 
undefined variable.


//$connection contains database connection handler
$result=mysql_query(select NULL as value,$connection);
$tmp=mysql_fetch_array($result);
$foo=$tmp[value];
if (!isset($foo)) echo(\$foo is not set but does not produce warning 
-$foo-);


OKi98

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



Re: [PHP-DB] variable with NULL value

2007-05-03 Thread James Gadrow

OKi98 wrote:

Hi,

one more question.

Why the variable, that contains NULL value appears to be not set. When 
you try to echo it the php does not produce warning about using 
undefined variable.


//$connection contains database connection handler
$result=mysql_query(select NULL as value,$connection);
$tmp=mysql_fetch_array($result);
$foo=$tmp[value];
if (!isset($foo)) echo(\$foo is not set but does not produce warning 
-$foo-);


OKi98


Someone correct me if I'm wrong but it appears that you should be using
if(!isset($tmp[value]) before assigning to $foo if you want to ensure 
that $foo will, indeed, be set.


--
Thanks,

Jim

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



Re: [PHP-DB] variable with NULL value

2007-05-03 Thread Chris

James Gadrow wrote:

OKi98 wrote:

Hi,

one more question.

Why the variable, that contains NULL value appears to be not set. When 
you try to echo it the php does not produce warning about using 
undefined variable.


//$connection contains database connection handler
$result=mysql_query(select NULL as value,$connection);
$tmp=mysql_fetch_array($result);
$foo=$tmp[value];
if (!isset($foo)) echo(\$foo is not set but does not produce warning 
-$foo-);


OKi98


Someone correct me if I'm wrong but it appears that you should be using
if(!isset($tmp[value]) before assigning to $foo if you want to ensure 
that $foo will, indeed, be set.


Yeh - you need to check before you do the assignment.

--
Postgresql  php tutorials
http://www.designmagick.com/

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