php-general Digest 23 Mar 2012 09:03:22 -0000 Issue 7740

Topics (messages 317190 through 317200):

Re: Thinking out loud - a continuation...
        317190 by: Jay Blanchard
        317198 by: Robert Cummings

set_error_handler() only triggering every Nth time
        317191 by: Daevid Vincent
        317199 by: Robert Cummings

MySQL table design
        317192 by: Chris Stinemetz
        317193 by: Stuart Dallas
        317194 by: Bastien
        317195 by: Chris Stinemetz
        317196 by: Jim Giner

make error
        317197 by: »ÆÕÑÔ´

Re: Got HTML5 History API + caching LICKED, I think, <grin>
        317200 by: rene7705

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


----------------------------------------------------------------------
--- Begin Message ---
[snip]
> At one point you indicated all the data was coming from one table. Can you 
> send me the table fields and indicate which fields are used to determine 
> parent child relationship? Also 2 sample rows of data which have a 
> relationship would be helpful.
[/snip]

Columns - tier1, tier2, tier3, tier4 etc. (ends with tier14)

Children of tier1 are tier2 -

select distinct tier2 from table where tier1 = "foo" and company = "1"
select distinct tier2 from table where tier1 = "bar" and company = "1"
etc.

Children of tier2 are tier3, etc.

        tier1           tier2           tier3
1,      executive,      ceo,            ceo
1,      executive,      vp-ops,                 vp-ops
1,      executive,      vp-admin,       vp-admin mgr
1,      executive,      vp-admin,       vp-admin ops mgr
1,      executive,      vp-admin,       vp-admin mgr
1,      executive,      vp-admin,       vp-admin clerk
1,      professional    pro-mgr         pro-admin
1,      professional    pro-IT          pro-dev
1,      professional    pro-IT          pro-infra
1,      professional    pro-IT          pro-dev
1,      technician      tech-admin      tech-admin mgr
1,      technician      tech-ops                tech-ops mgr

Thanks for all of your help. I know I am being a PITA.

--- End Message ---
--- Begin Message ---
On 12-03-22 03:54 PM, Jay Blanchard wrote:
[snip]
At one point you indicated all the data was coming from one table. Can you send 
me the table fields and indicate which fields are used to determine parent 
child relationship? Also 2 sample rows of data which have a relationship would 
be helpful.
[/snip]

Columns - tier1, tier2, tier3, tier4 etc. (ends with tier14)

Children of tier1 are tier2 -

select distinct tier2 from table where tier1 = "foo" and company = "1"
select distinct tier2 from table where tier1 = "bar" and company = "1"
etc.

Children of tier2 are tier3, etc.

        tier1           tier2           tier3
1,      executive,      ceo,            ceo
1,      executive,      vp-ops,                 vp-ops
1,      executive,      vp-admin,       vp-admin mgr
1,      executive,      vp-admin,       vp-admin ops mgr
1,      executive,      vp-admin,       vp-admin mgr
1,      executive,      vp-admin,       vp-admin clerk
1,      professional    pro-mgr         pro-admin
1,      professional    pro-IT          pro-dev
1,      professional    pro-IT          pro-infra
1,      professional    pro-IT          pro-dev
1,      technician      tech-admin      tech-admin mgr
1,      technician      tech-ops                tech-ops mgr

Thanks for all of your help. I know I am being a PITA.

Your data structure doesn't appear to be very ummm normalized... Nonetheless, the following should do it:

<?php

    //
    // Establish the root.
    //

    $company = 1;

    $query =
        "SELECT DISTINCT "
       ."   tier1 AS id "
       ."FROM "
       ."   tiers "
       ."WHERE "
       ."   company = {$company} ";

    $root = array();
    $children = array();
    if( $db->query( $query ) )
    {
        while( ($row = $db->fetchRow()) )
        {
            $id = $row['id'];

            unset( $child );

            $child = array
            (
                'id'       => $id,
                'parentId' => false,
                'children' => array();
            );

            $root[$id] = &$child;
            $children[$id][] = &$child;
        }
    }

    //
    // Establish the nested levels.
    //

    for( $tier = 2; $tier <= 14; $tier++ )
    {
        if( !($parents = &$children) )
        {
            break;
        }

        $parentTier = $tier - 1;

        $parentIds = array();
        foreach( array_keys( $parents ) as $parentId )
        {
            $parentIds[$parentId] = $db->quote( $parentId );
        }

        $query =
            "SELECT DISTINCT "
           ."   tier{$tier} AS id, "
           ."   tier{$parentTier} AS parentId "
           ."FROM "
           ."   tiers "
           ."WHERE "
           ."   company = {$company} "
           ."   AND "
           ."   tier{$parentTier} IN (".implode( ',', $parentIds ).") ";

        if( $db->query( $query ) )
        {
            unset( $children );
            $children = array();
            while( ($row = $db->fetchRow()) )
            {
                $id  = $row['id'];
                $pid = $row['parentId'];

                unset( $child );

                $child = array
                (
                    'id'       => $id,
                    'parentId' => $pid,
                    'children' => array();
                );

                $children[$id][] = &$child;

                foreach( $parents[$pid] as &$items )
                {
                    foreach( $items as &$item )
                    {
                        $item['children'][$id] = &$child;
                    }
                }
            }
        }
    }

    $json = JSON_encode( $root );
?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
Resending since I didn't get a single reply. Maybe it got lost?

-----Original Message-----
Sent: Tuesday, March 13, 2012 5:58 PM

I am implementing a custom error handler and started noticing some bizarre
behavior. Every Nth time I refresh the page, I see the error/output.

In my 'includes/common.inc.php' the key things are these:

        set_error_handler('php_error_handler');

        function php_error_handler($errno, $errstr, ...)
        {
           //does some stuff
           //calls php_custom_error_log()
        }

        function php_custom_error_log()
        {
                echo "php_custom_error_log : ".date('H:i:s');
        
                if ($error = error_get_last())
                {
                        var_dump(LOG_LEVEL, $error);
        
                //does more stuff
        }

My test page:

        <?php
        define('LOG_LEVEL', E_ALL ^ E_NOTICE);
        error_reporting(LOG_LEVEL);
        ini_set('display_errors','On');
        
        define('VM', true);
        define('DEVELOPMENT', false);
        
        ini_set('xdebug.var_display_max_children', 1000 ); 
        ini_set('xdebug.var_display_max_depth', 5 ); 
        
        require_once 'includes/common.inc.php';
        
        ###### BEGIN TEST #########
        
        foreach($empty as $k) echo $k;
        ?>

For those astute observers, you'll note that $empty is not an array and
therefore I expect an error message (well warning)

( ! ) Warning: Invalid argument supplied for foreach() in
/usr/home/vz/examples.videosz.com/error_handler_tests.php on line 20
Call Stack
#       Time    Memory  Function        Location
1       0.0005  663616  {main}( )       ../error_handler_tests.php:0

As I simply click 'refresh' on the browser I noticed that it was only
periodically working. I then deduced that it was directly related to the
number of apache threads. So if I had 15 then it would work every 15th
refresh:

developer@vm:/usr/local/etc/apache22$ ps aux | grep httpd
(standard input):39:root      15855  0.0  2.0 204156 20292  ??  Ss   28Feb12
1:33.48 /usr/local/sbin/httpd -k start
(standard input):48:www       89522  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):49:www       89523  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):50:www       89524  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):51:www       89525  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):52:www       89527  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):53:www       89528  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):54:www       89529  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):55:www       89530  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):56:www       89531  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):57:www       89532  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):58:www       89533  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):59:www       89534  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):60:www       89535  0.0  2.0 204156 20332  ??  I     8:03PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):61:www       89563  0.0  2.1 206204 21700  ??  I     8:17PM
0:00.10 /usr/local/sbin/httpd -k start
(standard input):62:www       89578  0.0  2.0 204156 20332  ??  I     8:22PM
0:00.01 /usr/local/sbin/httpd -k start
(standard input):74:developer 89587  0.0  0.1  9092  1196   1  S+    8:30PM
0:00.01 grep -inH --color httpd
 

124 <IfModule prefork.c>
125 StartServers      15
126 MinSpareServers   15
127 MaxSpareServers   20
128 ServerLimit       50
129 MaxClients        50
130 MaxRequestsPerChild  15
131 KeepAlive         Off
132 </IfModule>

Just to check and the time is updating each press and every 15th try I'd get
this:

php_custom_error_log : 19:54:20
int 30711
array
  'type' => int 8192
  'message' => string 'Directive 'register_globals' is deprecated in PHP 5.3
and greater' (length=65)
  'file' => string 'Unknown' (length=7)
  'line' => int 0

When I'd expect to see a message every time (with a new timestamp).

Then I REALLY looked at the 'message' part. "register_globals". WTF? That
isn't the error I expected.

Hmmm.. what happens if I move the second function inline to the first...

BAM! EVERY TIME it works perfectly.

So WTFF??! Why does moving it inline make any difference? All I suspect is
the $error = error_get_last() part. For some reason that isn't consistent.
And the other strange thing is that it's giving me erroneous error messages
(well, we do have register_globals on, but that's not the error I was
expecting).

Then I did another test replacing the foreach() with this statement:

        require_once "/foo.inc.php";

A few bizarre things about this too. For starters why do I get TWO error
messages. One WARNING from MY error handler and then a FATAL default PHP
one?! Sorta defeats my purpose.

        WARNING: require_once(/foo.inc.php) [function.require-once]:
                 failed to open stream: No such file or directory in
                 /usr/home/vz/examples.com/error_handler_tests.php on line
22

        Fatal error: require_once() [function.require]:
                 Failed opening required '/foo.inc.php'
(include_path='.:/home/SHARED')
                 in /usr/home/examples. com/error_handler_tests.php on line
22

Next if I print out php_error_handler($errno, ...) it says "2". And '2' is a
WARNING according to this page:
http://php.net/manual/en/errorfunc.constants.php Shouldn't it be "1"!?

developer@vm_daevid:/usr/local/etc/apache22$ php --version
PHP 5.3.6 with Suhosin-Patch (cli) (built: Apr 28 2011 14:20:48)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans

Running on FreeBSD.


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


--- End Message ---
--- Begin Message ---
On 12-03-22 03:57 PM, Daevid Vincent wrote:
Resending since I didn't get a single reply. Maybe it got lost?

-----Original Message-----
Sent: Tuesday, March 13, 2012 5:58 PM

I am implementing a custom error handler and started noticing some bizarre
behavior. Every Nth time I refresh the page, I see the error/output.

Have you tried sending headers that disable caching?

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
Hello List,

Is it possible to create a MySQL table with characters such as "." and
"[]" in the column headers? If so would you explain how?

Thank you,

Chris

--- End Message ---
--- Begin Message ---
On 23 Mar 2012, at 00:10, Chris Stinemetz wrote:

> Is it possible to create a MySQL table with characters such as "." and
> "[]" in the column headers? If so would you explain how?

Try putting the column names in backticks (`).

BUT... whatever the reason why you want to do that, IT'S WRONG.

Seriously, don't do it. It will cause you more problems than you think it will 
solve, and I don't even know what problem you think it will solve.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---

On 2012-03-22, at 8:10 PM, Chris Stinemetz <chrisstinem...@gmail.com> wrote:

> Hello List,
> 
> Is it possible to create a MySQL table with characters such as "." and
> "[]" in the column headers? If so would you explain how?
> 
> Thank you,
> 
> Chris
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Periods are not allowed, nor other characters that are reflected in file paths. 

You can use the back tick to wrap the field names, but I really don't recommend 
it. If you ever need to port this to another DB, it might not be as forgiving

Bastien

--- End Message ---
--- Begin Message ---
On Thu, Mar 22, 2012 at 7:42 PM, Stuart Dallas <stu...@3ft9.com> wrote:
> On 23 Mar 2012, at 00:10, Chris Stinemetz wrote:
>
>> Is it possible to create a MySQL table with characters such as "." and
>> "[]" in the column headers? If so would you explain how?
>
> Try putting the column names in backticks (`).
>
> BUT... whatever the reason why you want to do that, IT'S WRONG.
>
> Seriously, don't do it. It will cause you more problems than you think it 
> will solve, and I don't even know what problem you think it will solve.
>

I am just trying to preserve the source headers from the original data
I want to import into the table.

Thank you,

Chris

--- End Message ---
--- Begin Message ---
Leave the past behind.  You're moving forward.  And - for whatever reason 
that they were used originally, you now have the opportunity to rid yourself 
of column names that must be a pia to type all the time. 



--- End Message ---
--- Begin Message ---
Hello, I have a problem.
When I configure php with the parameter --with-mysql=/usr/local/mysql and
make, some errors happen. Below is the errors:
ext/mysql/php_mysql.c:995: undefined reference to `_mysqlnd_init'
ext/mysql/php_mysql.c:1012: undefined reference to `mysqlnd_connect'
ext/mysql/php_mysql.c:876: undefined reference to `_mysqlnd_init'
...
and so on.
Is there someone also come across this? Can anyone help me? Thanks!

-- 
黄昭源
*Best Wishes To You!*

--- End Message ---
--- Begin Message ---
Because some of you complained about the byte size of my homepage
http://mediabeez.ws (was 2.5mb due to artwork), I've invested some time in
shaving off quite a few bytes;

I've discovered that by using photoshop to reduce the animation image color
depth to "indexed color, 217 color", I can get the animation image file
size down to less than 50% of the original that was output by my
spriteGenerator-1.0.0

And you hardly notice the difference at all :)

I'm going to update http://mediabeez.ws later today, hopefully after I find
a way to do this with imagemagick, which my spriteGenerator uses.

And since I also use half the frames for my site logo of http://mediabeez.ws,
that animation file is now 297kb, down from 2mb.

--- End Message ---

Reply via email to