php-general Digest 6 Aug 2007 04:51:05 -0000 Issue 4945

Topics (messages 260209 through 260223):

Wierd error with xml_set_element_handler()
        260209 by: Bruce Steinback
        260210 by: Tijnema

Re: Check for well formed html
        260211 by: Kathleen Ballard

Adding to time having a timestamp
        260212 by: OOzy Pal
        260213 by: Stut

Get list of timezones from UTC offset
        260214 by: Norbert Wenzel

Re: Cannot send session cache limiter...
        260215 by: Nisse Engström

Re: Problems with file_get_contents() and local PHP file
        260216 by: Mike
        260217 by: Jan Reiter
        260218 by: Chris
        260220 by: Jan Reiter

PDO lastInsertID always returns zero for MySQL tables
        260219 by: Ken Tozier

Re: PDO lastInsertID always returns zero for MySQL tables [SOLVED]
        260221 by: Ken Tozier

About MySQL Tables
        260222 by: Kelvin Park
        260223 by: Robert Cummings

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Okay, I'm probably really stupid, but I can't figure this out.  I'm getting the 
error:

Fatal error: Function name must be a string in .../pages-stage/loginresp.php on 
line 205

(which is the xml_set_element_handler() call)

with this code:

  function startElement($parser, $name, $attrs) {
    global $value;
    $value = "";
  }

  function endElement($parser, $name) {
    global $value, $bypass, $status;
    ....
  }

  function charData($parser, $data) {
    global $value;
    $value = $data;
  }

  if (!isset($_GET["consentResp"])) {
    ...
  } else {
    ...
  }

  // Fallthru do getPresence
  // Okay, user is auth'd, now do getPresence to get members of BL
  $resp = doGetPresence($devId, $authToken, $baseUrl);
  // sigh - strip HTTP metadata
  $resp = strstr($resp, "<?");

  // Do XML parse - sets status, handles BL data if present
  $xml_parser = xml_parser_create();
  $xml_set_element_handler($xml_parser, 'startElement', 'endElement');
  $xml_set_character_data_handler($xml_parser, 'charData');
  $xml_parse($xml_parser, $resp, true);
  $xml_parser_free($xml_parser);

Any ideas? I've tried the line with single quotes, double quotes and no quotes, 
and various other odd attempts to figure it out.  I'm totally baffled.

    Many Thanks (in advance),
    Bruce Steinback




       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the 
tools to get online.
http://smallbusiness.yahoo.com/webhosting 

--- End Message ---
--- Begin Message ---
On 8/5/07, Bruce Steinback <[EMAIL PROTECTED]> wrote:
> Okay, I'm probably really stupid, but I can't figure this out.  I'm getting 
> the error:
>
> Fatal error: Function name must be a string in .../pages-stage/loginresp.php 
> on
> line 205
>
> (which is the xml_set_element_handler() call)
>
> with this code:
>
>  function startElement($parser, $name, $attrs) {
>    global $value;
>    $value = "";
>  }
>
>  function endElement($parser, $name) {
>    global $value, $bypass, $status;
>    ....
>  }
>
>  function charData($parser, $data) {
>    global $value;
>    $value = $data;
>  }
>
>  if (!isset($_GET["consentResp"])) {
>    ...
>  } else {
>    ...
>  }
>
>  // Fallthru do getPresence
>  // Okay, user is auth'd, now do getPresence to get members of BL
>  $resp = doGetPresence($devId, $authToken, $baseUrl);
>  // sigh - strip HTTP metadata
>  $resp = strstr($resp, "<?");
>
>  // Do XML parse - sets status, handles BL data if present
>  $xml_parser = xml_parser_create();
>  $xml_set_element_handler($xml_parser, 'startElement', 'endElement');

Uhm, why do you have a $ before xml_set_element_handler?

>  $xml_set_character_data_handler($xml_parser, 'charData');
>  $xml_parse($xml_parser, $resp, true);
>  $xml_parser_free($xml_parser);

And also before above functions?
>
> Any ideas? I've tried the line with single quotes, double quotes and no 
> quotes, and various other odd attempts to figure it out.  I'm totally baffled.
>
>    Many Thanks (in advance),
>    Bruce Steinback
>

let me (us) know if you fixed it.

Tijnema


-- 
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

--- End Message ---
--- Begin Message ---
Tedd,
Finally, I can give you an answer!  :)

You can use html tidy.  I did this before the php tidy function was fully
implemented, so I don't know the syntax for that.  But using tidy from the
command line you can set have it either correct errors (probably not what
you want) or just have it return an error flag and log the errors.

http://www.php.net/manual/en/ref.tidy.php

http://tidy.sourceforge.net/

Kathleen

-----Original Message-----
From: tedd [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 05, 2007 7:17 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Check for well formed html

Hi gang:

I have a client who wants to include html tags in his CMS.

I know that I can limit what tags he can use, but how can I check if 
the text is well formed with the tags permitted before storing it in 
his CMS?

Cheers,

tedd

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

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

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

How can I add a day to a date if I have a timestamp. Here is my line:

list($d,$m,$y,$dayname,$monthname,$am)=explode(' ',date('d m Y D M a',
$timestamp));

Thank you in advance

-- 
OOzy
Ubuntu-Feisty

--- End Message ---
--- Begin Message ---
OOzy Pal wrote:
How can I add a day to a date if I have a timestamp. Here is my line:

list($d,$m,$y,$dayname,$monthname,$am)=explode(' ',date('d m Y D M a',
$timestamp));

Thank you in advance

$timestamp = $timestamp + 86400;

A timestamp is a number of seconds and there are 86400 seconds in a day.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message --- As far as I understand it is only possible to create a DateTimeZone Object from a string, which describes the timezone.

On the other hand it is not possible (at least I did not find any possibility) to get the users tz string, it is only possible to get the current UTC offset. (via JavaScript or by doing some magic with the users IP)

I wonder if there is a possibility to get a list of possible timezones with a certain offset. I could extract this list from the timezone_abbreviations_list or check the offset for every item in the timezone_identifiers_list, but those solutions seem far too complicated and slow.

So is there a function like
     array timezone_guesses_get(int)
where int is the UTC offset in hours and array is a list of possible timezone names.

thanks,
Norbert

--- End Message ---
--- Begin Message ---
On Fri, 20 Jul 2007 16:39:51 -0500 (CDT), "Richard Lynch" wrote:

> Did you save it as UTF-8 with that byte-order-mark (BOM) thingie?
> 
> Does UTF-8 even HAVE a BOM?

<http://www.unicode.org/Public/UNIDATA/Index.txt>:

  "byte order mark        FEFF"


U+FEFF is <ef bb bf> in UTF-8.


/Nisse

--- End Message ---
--- Begin Message --- Hah, it works! I had to fiddle around a few other errors but that did the trick! Thank you so much. :)

-Mike
--- End Message ---
--- Begin Message ---
Nice to hear that!

If you expect heavy traffic on the site using that script you might want try
to save some DNS and http connection overhead by stating the url with
http://localhost/ and so on. Given that the server's OS is unix based, it
may also work to execute the php-script like a shell script if the php
environment is set accordingly. 
In case of a image processing script, this may take a huge load of work away
from your apache or wahterver server, and restrict it to the php processor
only. 
(the data stream won't be routed over the internet deamon and the webserver
on port 80)

In order to do so, try 
$buffer = `php /var/www/thescript.php`; // or whatever location your script
is in ...
Instead of 
$buffer = file_get_contents("http://localblah...";);

But if it's a rented server, apache overhead isn't your concern, so go on
and let your provider worry about it! :-D

Jan



-----Original Message-----
From: Mike [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 06, 2007 12:45 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Problems with file_get_contents() and local PHP file

Hah, it works! I had to fiddle around a few other errors but that did the 
trick! Thank you so much. :)

-Mike 

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

--- End Message ---
--- Begin Message ---
Jan Reiter wrote:
Nice to hear that!

If you expect heavy traffic on the site using that script you might want try
to save some DNS and http connection overhead by stating the url with
http://localhost/ and so on.

Which will most likely point to a different virtual host and cause you even more problems trying to track it down.

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

--- End Message ---
--- Begin Message ---
You've got a point about that. 

Try
<?php
echo file_get_contents("http://localhost/path/to/webdir";);
?>
First ... If you see your own webpage it's okay, else don't mess with it.



-----Original Message-----
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 06, 2007 2:51 AM
To: Jan Reiter
Cc: 'Mike'; [EMAIL PROTECTED]
Subject: Re: [PHP] Problems with file_get_contents() and local PHP file

Jan Reiter wrote:
> Nice to hear that!
> 
> If you expect heavy traffic on the site using that script you might want
try
> to save some DNS and http connection overhead by stating the url with
> http://localhost/ and so on.

Which will most likely point to a different virtual host and cause you 
even more problems trying to track it down.

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

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

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

In the past, I always used mysql_insert_id() and never had a problem, but now that I'm using PDO, I'm finding that it always returns zero. The tables are identical between the two methods but where mysql_insert_id works $pdo_connection->lastInsertID() doesn't.

The PDO documentation states that you need to feed lastInsertID something called a "sequence object." I'd never heard of those before so after some reading here http://www.mckoi.com/database/ SQLSyntax.html#7 it looks like you have to create these yourself . But MySQL tables already seem to have a built-in sequence (as evidenced by the auto_increment flag when creating tables) and creating another one for a given table could lead to id collisions.

So basically, the question is: Is it possible to get valid "lastInsertIds: using PDO with a MySQL database that mirrors the behavior of mysql_insert_id?

Thanks for any help

Ken

Here' the function.
The lastInsertID call comes in the 'else' branch of the "if (strpos ($query, 'insert') === false)" test

function query_database($inQuery)
{
        $query                  = $inQuery;
        $coersions              = null;
        $object_key             = null;
        $group_by_key   = null;
                
        if (is_array($inQuery))
        {
                $query                  = $inQuery['query'];
                $coersions              = $inQuery['coersions'];
                $object_key             = $inQuery['object_key'];
                $group_by_key   = $inQuery['group_by_key'];
        }
        
        try
        {
                // determine query type
                if (strpos($query, 'insert') === false)
                {
                        $rows                           = array();
                        $rowCounter                     = 0;
                        
                        foreach ($this->db->query($query, PDO::FETCH_NAMED) as 
$row)
                        {
                                $rowFields              = array();
                                $recordKey              = $rowCounter;
                                
                                foreach ($row as $key => $value)
                                {
                                        // remember this key if it matches the 
user specified object key
                                        if (($object_key != null) && ($key == 
$object_key))
                                                $recordKey              = 
$value;
                                        
                                        // perform user specified coersions
                                        if ($coersions != null)
                                                $value  = 
$this->coerce_value($value, $coersions[$key]);
                                        
                                        $rowFields[$key]                        
        = $value;
                                }
                                
                                // perform grouping if requested
                                if ($group_by_key == null)
                                        $rows[$recordKey]               = 
$rowFields;
                                else
                                {
                                        $groupKey       = 
$rowFields[$group_by_key];
                                                
                                        if ($rows[$groupKey] == null)
                                                $rows[$groupKey]        = 
array();
                                        
                                        $rows[$groupKey][]              = 
$rowFields;
                                }
                                
                                $rowCounter++;
                        }
                        
                        return $rows;
                }
                else
                {
                        // next line prints OK on inserts
                        echo 'query type was: insert<br>';
                        
                        // but this always returns zero
                        return ($this->db->lastInsertId());
                }
        }
        catch (PDOException $error)
        {
                print "Error!: " . $error->getMessage() . "<br/>";
                die();
        }
}

--- End Message ---
--- Begin Message ---
Disregard.

After more head scratching I found that I was branching to the 'insert' handler without calling this->db->query($query).


On Aug 5, 2007, at 9:18 PM, Ken Tozier wrote:

Hi

In the past, I always used mysql_insert_id() and never had a problem, but now that I'm using PDO, I'm finding that it always returns zero. The tables are identical between the two methods but where mysql_insert_id works $pdo_connection->lastInsertID() doesn't.

The PDO documentation states that you need to feed lastInsertID something called a "sequence object." I'd never heard of those before so after some reading here http://www.mckoi.com/database/ SQLSyntax.html#7 it looks like you have to create these yourself . But MySQL tables already seem to have a built-in sequence (as evidenced by the auto_increment flag when creating tables) and creating another one for a given table could lead to id collisions.

So basically, the question is: Is it possible to get valid "lastInsertIds: using PDO with a MySQL database that mirrors the behavior of mysql_insert_id?

Thanks for any help

Ken

Here' the function.
The lastInsertID call comes in the 'else' branch of the "if (strpos ($query, 'insert') === false)" test

function query_database($inQuery)
{
        $query                  = $inQuery;
        $coersions              = null;
        $object_key             = null;
        $group_by_key   = null;
                
        if (is_array($inQuery))
        {
                $query                  = $inQuery['query'];
                $coersions              = $inQuery['coersions'];
                $object_key             = $inQuery['object_key'];
                $group_by_key   = $inQuery['group_by_key'];
        }
        
        try
        {
                // determine query type
                if (strpos($query, 'insert') === false)
                {
                        $rows                           = array();
                        $rowCounter                     = 0;
                        
                        foreach ($this->db->query($query, PDO::FETCH_NAMED) as 
$row)
                        {
                                $rowFields              = array();
                                $recordKey              = $rowCounter;
                                
                                foreach ($row as $key => $value)
                                {
                                        // remember this key if it matches the 
user specified object key
                                        if (($object_key != null) && ($key == 
$object_key))
                                                $recordKey              = 
$value;
                                        
                                        // perform user specified coersions
                                        if ($coersions != null)
                                                $value  = 
$this->coerce_value($value, $coersions[$key]);
                                        
                                        $rowFields[$key]                        
        = $value;
                                }
                                
                                // perform grouping if requested
                                if ($group_by_key == null)
                                        $rows[$recordKey]               = 
$rowFields;
                                else
                                {
                                        $groupKey       = 
$rowFields[$group_by_key];
                                                
                                        if ($rows[$groupKey] == null)
                                                $rows[$groupKey]        = 
array();
                                        
                                        $rows[$groupKey][]              = 
$rowFields;
                                }
                                
                                $rowCounter++;
                        }
                        
                        return $rows;
                }
                else
                {
                        // next line prints OK on inserts
                        echo 'query type was: insert<br>';
                        
                        // but this always returns zero
                        return ($this->db->lastInsertId());
                }
        }
        catch (PDOException $error)
        {
                print "Error!: " . $error->getMessage() . "<br/>";
                die();
        }
}

--- End Message ---
--- Begin Message ---
I have two tables that share product codes to relate data.
One table is called IMAGE, and another one is called the PRODUCT.
There are more than one image for every product, for example product code 1122 will have 3 images and 4938 will have 5 images within the IMAGE table. Since all my product information is stored in PRODUCT table except for the image file names (e.g. 1122_1.jpg, 1122_2.jpg or 4938_1.gif), I have to build the following query: SELECT * FROM PRODUCT, IMAGE WHERE PRODUCT.productcode = IMAGE.productcode. However, this causes a little problem. When I print out all the product information with its images, more than one copy of a product is printed out (because of multiple images for each product). I'm still looking for a way to build a query string so that I could have only one image displayed per product (so that a user can click on the product to view more images).

Do you know how this problem can be best approached?

--- End Message ---
--- Begin Message ---
On Sun, 2007-08-05 at 21:35 -0700, Kelvin Park wrote:
> I have two tables that share product codes to relate data.
> One table is called IMAGE, and another one is called the PRODUCT.
> There are more than one image for every product, for example product 
> code 1122 will have 3 images and 4938 will have 5 images within the 
> IMAGE table. Since all my product information is stored in PRODUCT table 
> except for the image file names (e.g. 1122_1.jpg, 1122_2.jpg or 
> 4938_1.gif), I have to build the following query: SELECT * FROM PRODUCT, 
> IMAGE WHERE PRODUCT.productcode = IMAGE.productcode. However, this 
> causes a little problem. When I print out all the product information 
> with its images, more than one copy of a product is printed out (because 
> of multiple images for each product). I'm still looking for a way to 
> build a query string so that I could have only one image displayed per 
> product (so that a user can click on the product to view more images).
>
> Do you know how this problem can be best approached?

You can use a group by clause to cause the result set to normalize on
the grouping criteria (productcode would be a good candidate).

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---

Reply via email to