php-general Digest 22 Sep 2012 08:25:22 -0000 Issue 7975

2012-09-22 Thread php-general-digest-help

php-general Digest 22 Sep 2012 08:25:22 - Issue 7975

Topics (messages 319186 through 319191):

Re: PHP Bounce messages
319186 by: tamouse mailing lists

Re: Bounce messages
319187 by: Lester Caine
319189 by: David McGlone
319190 by: Lester Caine

Re: PHP Re: PHP Bounce messages
319188 by: Tim Streater

Intermittent error on hosted service
319191 by: Lester Caine

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Fri, Sep 21, 2012 at 4:17 AM, Tim Streater t...@clothears.org.uk wrote:
 On 21 Sep 2012 at 08:40, Lester Caine les...@lsces.co.uk wrote:

 I know that the php list are one of the 'reply to sender' email handling camp
 rather than reply to list.

 I don't understand this. I reply (not that I mail that often) just to the 
 list, if possible. Why would I do anything else?

I believe Lester is referring to the behaviour of the Reply-To: field
sent by the list serv, which is the sender's address. Some other
listservs put the list reply address in Reply-To:
---End Message---
---BeginMessage---

Ashley Sheridan wrote:

On 09/21/2012 12:40 AM, Lester Caine wrote:
 I know that the php list are one of the 'reply to sender' email handling
 camp rather than reply to list. I can cope with that now and handle the
 multiple reply address problem this end so I ONLY reply to list. BUT is
 there no way of cleaning up the bounce emails we all get when posting to
 the list(s)?

 ( Waits to delete all the bounce messages for this post :) )


Doing a little checking on your IP address, I have found that your mail
server IP is listed on a black list.  Check the link below.

http://mxtoolbox.com/SuperTool.aspx?action=blacklist%3a213.123.20.127

This could be the source of your bounce messages.


Well that is BT Internet ;) Not a lot I can do about that ...


I sporadically get a lot of messages that appear as bounces where people on the
list filter out replies and make you sign up to some web service to prove you're
a real person. Is that the sort of bounce you're talking about?


Yes ... I posted a reply earlier, and got three 'spam' warnings as well as the 
copy of my post. Actually it's not as bad as it has been ... I was expecting a 
few more after I posted the comment.


And Yes tamouse ... it's having to replace a block of return addresses with just 
the list address to tidy things up. A long list of addresses can build up when 
everyone uses 'reply all' where as many other lists just need 'reply' so 
nowadays I only use reply - and hopefully remember to change to the the list 
address :)


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
---End Message---
---BeginMessage---
On Friday, September 21, 2012 11:31:36 PM Lester Caine wrote:
 Ashley Sheridan wrote:
  On 09/21/2012 12:40 AM, Lester Caine wrote:
   I know that the php list are one of the 'reply to sender' email
   handling
   camp rather than reply to list. I can cope with that now and handle the
   multiple reply address problem this end so I ONLY reply to list. BUT is
   there no way of cleaning up the bounce emails we all get when posting
   to
   the list(s)?
   
   ( Waits to delete all the bounce messages for this post :) )
  
  Doing a little checking on your IP address, I have found that your mail
  server IP is listed on a black list.  Check the link below.
  
  http://mxtoolbox.com/SuperTool.aspx?action=blacklist%3a213.123.20.127
  
  This could be the source of your bounce messages.
 
 Well that is BT Internet ;) Not a lot I can do about that ...
 
  I sporadically get a lot of messages that appear as bounces where people
  on the list filter out replies and make you sign up to some web service
  to prove you're a real person. Is that the sort of bounce you're talking
  about?
 
 Yes ... I posted a reply earlier, and got three 'spam' warnings as well as
 the copy of my post. Actually it's not as bad as it has been ... I was
 expecting a few more after I posted the comment.
 
 And Yes tamouse ... it's having to replace a block of return addresses with
 just the list address to tidy things up. A long list of addresses can build
 up when everyone uses 'reply all' where as many other lists just need
 'reply' so nowadays I only use reply - and hopefully remember to change to
 the the list address :)

I use reply to mailing list in Kontact.
 -- 
David M.
David's Webhosting and consulting.
---End Message---
---BeginMessage---

David McGlone wrote:


Re: [PHP] Bounce messages

2012-09-22 Thread Lester Caine

David McGlone wrote:

And Yes tamouse ... it's having to replace a block of return addresses with
just the list address to tidy things up. A long list of addresses can build
up when everyone uses 'reply all' where as many other lists just need
'reply' so nowadays I only use reply - and hopefully remember to change to
the the list address:)

I use reply to mailing list in Kontact.


I have looked ;)
But importing 12+Gb of past history going back to 1998 was not practical.
ONE of these days I will get all the important stuff archived in my PHP based 
contact management system but it's still on the TODO pile while I waste time 
re-working the code to make it compliant with the lasted 'vision' of PHP :)


But YES that is a button that all email clients would benefit from!

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

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



[PHP] Intermittent error on hosted service

2012-09-22 Thread Lester Caine

A PHP Error was encountered
Severity: Warning
Message: require(): Unable to allocate memory for pool.
Filename: core/Common.php
Line Number: 145

Where should I be looking to fix this problem?
OTHER than switching off displaying warnings ... but the site code IS currently 
set to off, so that is another 'problem' finding out why it is displayed.


It's a little academic as I've now moved the sites to one of my own machines 
simply to get the customers working again, but the hosting service are saying 
'works for me' so I could do with a little more ammunition :)


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

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



[PHP] Need help to understand a code

2012-09-22 Thread Ashickur Rahman Noor
Hi all

I need some help to understand a code. The code is like this

$result = mysql_query($sSQL) or die(err:  . mysql_error().$sSQL);
 if($row = mysql_fetch_array($result))
 {
   foreach($row as $key =$value){ $$key=$value;}
 }


I don't get the code from the foreach loop.
--
Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
2048R/89C932E1 http://goo.gl/TkP5U
Coordinator - Public Relation Cell, FOSS Bangladesh
http://fossbd.org/  Mozilla
Reps http://reps.mozilla.org
01199151550, 01551151550


Re: [PHP] Need help to understand a code

2012-09-22 Thread Stefan Wixfort

On 22.09.2012 12:34, Ashickur Rahman Noor wrote:

Hi all

I need some help to understand a code. The code is like this

$result = mysql_query($sSQL) or die(err:  . mysql_error().$sSQL);

 if($row = mysql_fetch_array($result))
 {
   foreach($row as $key =$value){ $$key=$value;}
 }



I don't get the code from the foreach loop.


I assume that you mean the meaning of $$key = $value.
This is a variable variable[1]
This means if you have a key in your array named dino then you assign 
$dino the value of $value for the current row.


so: $key = 'dino', $value = 'saur'
= $$key = $value = $$key = 'saur' = $dino = 'saur'

Hope this was somewhat helpful and understandable.

[1] http://php.net/manual/en/language.variables.variable.php


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



[PHP] Re: Need help to understand a code

2012-09-22 Thread Maciek Sokolewicz

On 22-09-2012 12:34, Ashickur Rahman Noor wrote:

Hi all

I need some help to understand a code. The code is like this

$result = mysql_query($sSQL) or die(err:  . mysql_error().$sSQL);

 if($row = mysql_fetch_array($result))
 {
   foreach($row as $key =$value){ $$key=$value;}
 }



I don't get the code from the foreach loop.
It simply assigns all values from the array to variables, which have the 
name of the keys.


So basically what happens is:
$array = array('a'=1, 'b'=2, 'c'=3);
foreach($array as $key=$val) {
   $$key = $val;
}

will result in the creation of:
$a = 1;
$b = 2;
$c = 3;

$$foo means I want a variable whose name is contained in the variable 
$foo. So if $foo has the value 'bar', then you'll actually be saying I 
want a variable whose name is 'bar': $bar.


So:
$foo = 'bar';
$bar = 'this works!';

echo $$foo; // returns this works!



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



Re: [PHP] Re: Need help to understand a code

2012-09-22 Thread Ashley Sheridan
On Sat, 2012-09-22 at 13:13 +0200, Maciek Sokolewicz wrote:

 On 22-09-2012 12:34, Ashickur Rahman Noor wrote:
  Hi all
 
  I need some help to understand a code. The code is like this
 
  $result = mysql_query($sSQL) or die(err:  . mysql_error().$sSQL);
   if($row = mysql_fetch_array($result))
   {
 foreach($row as $key =$value){ $$key=$value;}
   }
 
 
  I don't get the code from the foreach loop.
 It simply assigns all values from the array to variables, which have the 
 name of the keys.
 
 So basically what happens is:
 $array = array('a'=1, 'b'=2, 'c'=3);
 foreach($array as $key=$val) {
 $$key = $val;
 }
 
 will result in the creation of:
 $a = 1;
 $b = 2;
 $c = 3;
 
 $$foo means I want a variable whose name is contained in the variable 
 $foo. So if $foo has the value 'bar', then you'll actually be saying I 
 want a variable whose name is 'bar': $bar.
 
 So:
 $foo = 'bar';
 $bar = 'this works!';
 
 echo $$foo; // returns this works!
 
 
 


Be careful with this though. I'm working on fixing some old code that
someone wrote. They used this technique to update their code when it
got moved to a server where register_globals was turned off.
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: Need help to understand a code

2012-09-22 Thread Ashickur Rahman Noor
Hi Ashley

I am updating some one code. Thanks for the notify.

Thanks to all. Now I get that.
--
Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
2048R/89C932E1 http://goo.gl/TkP5U
Coordinator - Public Relation Cell, FOSS Bangladesh
http://fossbd.org/  Mozilla
Reps http://reps.mozilla.org
01199151550, 01551151550


Re: [PHP] Re: Need help to understand a code

2012-09-22 Thread Ashley Sheridan
On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:

 Hi Ashley
 
 I am updating some one code. Thanks for the notify.
 
 Thanks to all. Now I get that.
 --
 Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
 2048R/89C932E1 http://goo.gl/TkP5U
 Coordinator - Public Relation Cell, FOSS Bangladesh
 http://fossbd.org/  Mozilla
 Reps http://reps.mozilla.org
 01199151550, 01551151550


It's probably fine doing that for your example, as the content coming
from the database will be content you expect, but be wary of using it on
any of the user-generated arrays like $_GET, or $_POST.

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




Re: [PHP] Re: Need help to understand a code

2012-09-22 Thread Matijn Woudt
Op 22 sep. 2012 13:47 schreef Ashley Sheridan a...@ashleysheridan.co.uk
het volgende:

 On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:

  Hi Ashley
 
  I am updating some one code. Thanks for the notify.
 
  Thanks to all. Now I get that.
  --
  Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
  2048R/89C932E1 http://goo.gl/TkP5U
  Coordinator - Public Relation Cell, FOSS Bangladesh
  http://fossbd.org/  Mozilla
  Reps http://reps.mozilla.org
  01199151550, 01551151550


 It's probably fine doing that for your example, as the content coming
 from the database will be content you expect, but be wary of using it on
 any of the user-generated arrays like $_GET, or $_POST.


And a few months/years later you decide to add a new column to your db
which has the same name as one of the variables you're already using and
the script starts acting very strange...
People should stop using bad coding habits like these..

- Matijn


RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Samuel Lopes Grigolato
+1 to bad maintainability of the code.

As a suggestion, one better solution could be something like:

[...]

class Entity {
   public $id;
   public $name;
}

[...]

$entity = new Entity();
foreach [...]
  $entity-$$key = $value;  

[...]

And, of course, never ever use * in SQL queries.

Samuel.

-Mensagem original-
De: Matijn Woudt [mailto:tijn...@gmail.com] 
Enviada em: sábado, 22 de setembro de 2012 11:02
Para: a...@ashleysheridan.co.uk
Cc: Ashickur Rahman Noor; PHP List
Assunto: Re: [PHP] Re: Need help to understand a code

Op 22 sep. 2012 13:47 schreef Ashley Sheridan a...@ashleysheridan.co.uk het 
volgende:

 On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:

  Hi Ashley
 
  I am updating some one code. Thanks for the notify.
 
  Thanks to all. Now I get that.
  --
  Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
  2048R/89C932E1 http://goo.gl/TkP5U Coordinator - Public Relation 
  Cell, FOSS Bangladesh http://fossbd.org/  Mozilla Reps 
  http://reps.mozilla.org 01199151550, 01551151550


 It's probably fine doing that for your example, as the content coming 
 from the database will be content you expect, but be wary of using it 
 on any of the user-generated arrays like $_GET, or $_POST.


And a few months/years later you decide to add a new column to your db which 
has the same name as one of the variables you're already using and the script 
starts acting very strange...
People should stop using bad coding habits like these..

- Matijn


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



Re: RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Ashley Sheridan


Samuel Lopes Grigolato samuel.grigol...@gmail.com wrote:

+1 to bad maintainability of the code.

As a suggestion, one better solution could be something like:

[...]

class Entity {
   public $id;
   public $name;
}

[...]

$entity = new Entity();
foreach [...]
  $entity-$$key = $value;

[...]

And, of course, never ever use * in SQL queries.

Samuel.

-Mensagem original-
De: Matijn Woudt [mailto:tijn...@gmail.com]
Enviada em: sábado, 22 de setembro de 2012 11:02
Para: a...@ashleysheridan.co.uk
Cc: Ashickur Rahman Noor; PHP List
Assunto: Re: [PHP] Re: Need help to understand a code

Op 22 sep. 2012 13:47 schreef Ashley Sheridan
a...@ashleysheridan.co.uk het volgende:

 On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:

  Hi Ashley
 
  I am updating some one code. Thanks for the notify.
 
  Thanks to all. Now I get that.
  --
  Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
  2048R/89C932E1 http://goo.gl/TkP5U Coordinator - Public Relation
  Cell, FOSS Bangladesh http://fossbd.org/  Mozilla Reps
  http://reps.mozilla.org 01199151550, 01551151550


 It's probably fine doing that for your example, as the content coming

 from the database will be content you expect, but be wary of using it

 on any of the user-generated arrays like $_GET, or $_POST.


And a few months/years later you decide to add a new column to your db
which has the same name as one of the variables you're already using
and the script starts acting very strange...
People should stop using bad coding habits like these..

- Matijn


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

there's nothing wrong with using * in queries.

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

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



Re: RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Maciek Sokolewicz

On 22-09-2012 16:19, Samuel Lopes Grigolato wrote:

+1 to bad maintainability of the code.

As a suggestion, one better solution could be something like:

[...]

class Entity {
public $id;
public $name;
}

[...]

$entity = new Entity();
foreach [...]
   $entity-$$key = $value;

[...]

And, of course, never ever use * in SQL queries.

Samuel.



If you're doing it that way, just use mysqli and then mysqli_result's 
fetch_object with your Entity as the class. ie:

$result = $mysqli-query('some query');
$entity = $result-fetch_object('Entity');


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



RES: RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Samuel Lopes Grigolato
I disagree with you Ashley, some arguments can be found here: 
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx

Using explicit columns names in the select clause is, IMHO, at least a good 
documentation for what is being requested to the database layer.

+1 to Maciek's suggestion, had totally forgotten this one.

Cheers.

-Mensagem original-
De: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Enviada em: sábado, 22 de setembro de 2012 11:52
Para: Samuel Lopes Grigolato; 'PHP List'
Assunto: Re: RES: [PHP] Re: Need help to understand a code



Samuel Lopes Grigolato samuel.grigol...@gmail.com wrote:

+1 to bad maintainability of the code.

As a suggestion, one better solution could be something like:

[...]

class Entity {
   public $id;
   public $name;
}

[...]

$entity = new Entity();
foreach [...]
  $entity-$$key = $value;

[...]

And, of course, never ever use * in SQL queries.

Samuel.

-Mensagem original-
De: Matijn Woudt [mailto:tijn...@gmail.com] Enviada em: sábado, 22 de 
setembro de 2012 11:02
Para: a...@ashleysheridan.co.uk
Cc: Ashickur Rahman Noor; PHP List
Assunto: Re: [PHP] Re: Need help to understand a code

Op 22 sep. 2012 13:47 schreef Ashley Sheridan
a...@ashleysheridan.co.uk het volgende:

 On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:

  Hi Ashley
 
  I am updating some one code. Thanks for the notify.
 
  Thanks to all. Now I get that.
  --
  Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
  2048R/89C932E1 http://goo.gl/TkP5U Coordinator - Public Relation 
  Cell, FOSS Bangladesh http://fossbd.org/  Mozilla Reps 
  http://reps.mozilla.org 01199151550, 01551151550


 It's probably fine doing that for your example, as the content coming

 from the database will be content you expect, but be wary of using it

 on any of the user-generated arrays like $_GET, or $_POST.


And a few months/years later you decide to add a new column to your db 
which has the same name as one of the variables you're already using 
and the script starts acting very strange...
People should stop using bad coding habits like these..

- Matijn


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

there's nothing wrong with using * in queries.

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.


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



Re: RES: RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Ashley Sheridan
On Sat, 2012-09-22 at 12:12 -0300, Samuel Lopes Grigolato wrote:

 I disagree with you Ashley, some arguments can be found here: 
 http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx
 
 Using explicit columns names in the select clause is, IMHO, at least a good 
 documentation for what is being requested to the database layer.
 
 +1 to Maciek's suggestion, had totally forgotten this one.
 
 Cheers.
 
 -Mensagem original-
 De: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
 Enviada em: sábado, 22 de setembro de 2012 11:52
 Para: Samuel Lopes Grigolato; 'PHP List'
 Assunto: Re: RES: [PHP] Re: Need help to understand a code
 
 
 
 Samuel Lopes Grigolato samuel.grigol...@gmail.com wrote:
 
 +1 to bad maintainability of the code.
 
 As a suggestion, one better solution could be something like:
 
 [...]
 
 class Entity {
public $id;
public $name;
 }
 
 [...]
 
 $entity = new Entity();
 foreach [...]
   $entity-$$key = $value;
 
 [...]
 
 And, of course, never ever use * in SQL queries.
 
 Samuel.
 
 -Mensagem original-
 De: Matijn Woudt [mailto:tijn...@gmail.com] Enviada em: sábado, 22 de 
 setembro de 2012 11:02
 Para: a...@ashleysheridan.co.uk
 Cc: Ashickur Rahman Noor; PHP List
 Assunto: Re: [PHP] Re: Need help to understand a code
 
 Op 22 sep. 2012 13:47 schreef Ashley Sheridan
 a...@ashleysheridan.co.uk het volgende:
 
  On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:
 
   Hi Ashley
  
   I am updating some one code. Thanks for the notify.
  
   Thanks to all. Now I get that.
   --
   Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
   2048R/89C932E1 http://goo.gl/TkP5U Coordinator - Public Relation 
   Cell, FOSS Bangladesh http://fossbd.org/  Mozilla Reps 
   http://reps.mozilla.org 01199151550, 01551151550
 
 
  It's probably fine doing that for your example, as the content coming
 
  from the database will be content you expect, but be wary of using it
 
  on any of the user-generated arrays like $_GET, or $_POST.
 
 
 And a few months/years later you decide to add a new column to your db 
 which has the same name as one of the variables you're already using 
 and the script starts acting very strange...
 People should stop using bad coding habits like these..
 
 - Matijn
 
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
 http://www.php.net/unsub.php
 
 there's nothing wrong with using * in queries.
 
 --
 Sent from my Android phone with K-9 Mail. Please excuse my brevity.
 


There are plenty of times that you need all fields from a table though.
I go by the rule that if I need less than two thirds of the fields of a
table, then I specify the fields I need, otherwise, it's easier to go
with *.

I've looked at the link you posted. The join issue is too broad. I use *
with joins, but avoid the conflicts by specifying the table name, still
going by the ⅔ rule above on a table by table basis. Of course, if there
are tables used in the join that are not necessary to the actual output,
I won't include them in the list, but I may do something like this:

SELECT a.a, a.b, a.c, b.*
FROM a
LEFT JOIN a on a.a = b.a

I would say that if you're in the position of writing the queries then
you should be aware of the database schema, so using the query as a form
of documentation shouldn't be a factor. Of course there are occasions
where the database is updated and breaks code, in which case specifying
all the field names would potentially avoid that, but procedures should
be in place which would at least make you aware of such updates to allow
you to plan for them.



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




RES: RES: RES: [PHP] Re: Need help to understand a code

2012-09-22 Thread Samuel Lopes Grigolato
When I said that it’s a form of documentation, I was saying that I think it’s 
better to know everything the script is using from the tables right on the SQL 
command, without the need to inspect all the code, for example:

 

SELECT * FROM a;

$values = some_fetch_array_thing

[…] bunch of lines of code

echo $values[“column1”];

[…] another bunch of code

echo $values[“column2”];

 

In my opinion it’s is easier to forget that column2 is being utilized by this 
script, than if it was explicit in the SQL command. Of course, if the lifecycle 
of the array fetched from the resultset doesn’t spread too much, there isn’t 
any problem.

 

Besides that, I’ve got your points =). The “a.*” thing successfully beats the 
join problem.

 

One last point: “Of course there are occasions where the database is updated 
and breaks code, in which case specifying all the field names would potentially 
avoid that”, we should only declare in the SELECT clause fields we’re actually 
using along the script, and even if we go with the “*” way the code will broke 
eventually with schema changes.

 

Regards.

 

De: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Enviada em: sábado, 22 de setembro de 2012 12:35
Para: Samuel Lopes Grigolato
Cc: 'PHP List'
Assunto: Re: RES: RES: [PHP] Re: Need help to understand a code

 

On Sat, 2012-09-22 at 12:12 -0300, Samuel Lopes Grigolato wrote: 

 
I disagree with you Ashley, some arguments can be found here: 
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx
 
Using explicit columns names in the select clause is, IMHO, at least a good 
documentation for what is being requested to the database layer.
 
+1 to Maciek's suggestion, had totally forgotten this one.
 
Cheers.
 
-Mensagem original-
De: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Enviada em: sábado, 22 de setembro de 2012 11:52
Para: Samuel Lopes Grigolato; 'PHP List'
Assunto: Re: RES: [PHP] Re: Need help to understand a code
 
 
 
Samuel Lopes Grigolato samuel.grigol...@gmail.com wrote:
 
+1 to bad maintainability of the code.
 
As a suggestion, one better solution could be something like:
 
[...]
 
class Entity {
   public $id;
   public $name;
}
 
[...]
 
$entity = new Entity();
foreach [...]
  $entity-$$key = $value;
 
[...]
 
And, of course, never ever use * in SQL queries.
 
Samuel.
 
-Mensagem original-
De: Matijn Woudt [mailto:tijn...@gmail.com] Enviada em: sábado, 22 de 
setembro de 2012 11:02
Para: a...@ashleysheridan.co.uk
Cc: Ashickur Rahman Noor; PHP List
Assunto: Re: [PHP] Re: Need help to understand a code
 
Op 22 sep. 2012 13:47 schreef Ashley Sheridan
a...@ashleysheridan.co.uk het volgende:
 
 On Sat, 2012-09-22 at 17:43 +0600, Ashickur Rahman Noor wrote:
 
  Hi Ashley
 
  I am updating some one code. Thanks for the notify.
 
  Thanks to all. Now I get that.
  --
  Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck
  2048R/89C932E1 http://goo.gl/TkP5U Coordinator - Public Relation 
  Cell, FOSS Bangladesh http://fossbd.org/  Mozilla Reps 
  http://reps.mozilla.org 01199151550, 01551151550
 
 
 It's probably fine doing that for your example, as the content coming
 
 from the database will be content you expect, but be wary of using it
 
 on any of the user-generated arrays like $_GET, or $_POST.
 
 
And a few months/years later you decide to add a new column to your db 
which has the same name as one of the variables you're already using 
and the script starts acting very strange...
People should stop using bad coding habits like these..
 
- Matijn
 
 
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php
 
there's nothing wrong with using * in queries.
 
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
 


There are plenty of times that you need all fields from a table though. I go by 
the rule that if I need less than two thirds of the fields of a table, then I 
specify the fields I need, otherwise, it's easier to go with *.

I've looked at the link you posted. The join issue is too broad. I use * with 
joins, but avoid the conflicts by specifying the table name, still going by the 
⅔ rule above on a table by table basis. Of course, if there are tables used in 
the join that are not necessary to the actual output, I won't include them in 
the list, but I may do something like this:

SELECT a.a, a.b, a.c, b.*
FROM a
LEFT JOIN a on a.a = b.a

I would say that if you're in the position of writing the queries then you 
should be aware of the database schema, so using the query as a form of 
documentation shouldn't be a factor. Of course there are occasions where the 
database is updated and breaks code, in which case specifying all the field 
names would potentially avoid that, but procedures should be in place which 
would at least make you aware of such updates to allow you to plan 

[PHP] Day after Friday

2012-09-22 Thread Tedd Sperling
Hi gang:

I know it's the Day after Friday, but I'm asking a off-topic question anyway -- 
sorry.

Normally, I teach a PHP class at the local college, but it got canceled (don't 
ask why) -- now I'm teaching Java.

So, can anyone recommend a Java list that is similar to this list?

Cheers,

tedd


_
t...@sperling.com
http://sperling.com


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



Re: [PHP] Day after Friday

2012-09-22 Thread Paul M Foster
On Sat, Sep 22, 2012 at 01:05:51PM -0400, Tedd Sperling wrote:

 Hi gang:
 
 I know it's the Day after Friday, but I'm asking a off-topic question anyway 
 -- sorry.
 
 Normally, I teach a PHP class at the local college, but it got canceled 
 (don't ask why) -- now I'm teaching Java.
 
 So, can anyone recommend a Java list that is similar to this list?

Off off topic...

Who the hell cancels a PHP class? Do they not realize damn near the
whole internet runs on PHP? Wordpress, Drupal, Joomla, Facebook ad
nauseum, not to mention Symfony, CakePHP, Code Igniter, etc.
Administrators! Ach!

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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