php-general Digest 18 Feb 2006 09:03:46 -0000 Issue 3970

Topics (messages 230662 through 230679):

What does a "?" represent
        230662 by: Jeff
        230663 by: Shaunak Kashyap
        230664 by: tg-php.gryffyndevelopment.com
        230668 by: Satyam
        230669 by: Jeff

Re: Problem with HUGE floating values and fmod
        230665 by: Curt Zirzow

URL problem
        230666 by: Jesús Alain Rodríguez Santos
        230667 by: Shaunak Kashyap

Re: array_map help
        230670 by: Mark Steudel

Re: Last Sunday in September?
        230671 by: Joel Leibow

Session Locking Up
        230672 by: Ray Hauge
        230675 by: Ray Hauge

Re: anyone care to explain the logic behind this output ....
        230673 by: David Tulloh

DB Error ??? help please ...
        230674 by: Mehmet Fatih Akbulut

Re: Saving a BLOB image to a file (SOLVED)
        230676 by: Gerry Danen

Logging visitors path and presenting this to visitors
        230677 by: Peter Lauri
        230678 by: Robert Cummings

"isset" or "array_key_exists"?
        230679 by: Nikolay Rastegaev

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 ---
In the some code I'm working with I see many database queries using the
PEAR DB class where  "?" is used for a value in the SQL.  What is the
rule for using "?" in this way what value does it take.

Example code.   

     $ticket=$db->getRow(
            "SELECT id,department,`from`, cc, bcc FROM tickets WHERE
id=?",
            array($tid)
        );

Jeff

--- End Message ---
--- Begin Message ---
I'm not sure if these completely answer your question but they might get
you started:

http://dev.mysql.com/doc/refman/4.1/en/mysql-stmt-prepare.html
http://dev.mysql.com/doc/refman/4.1/en/mysql-stmt-execute.html

Shaunak Kashyap
 
Senior Web Developer
WPT Enterprises, Inc.
5700 Wilshire Blvd., Suite 350
Los Angeles, CA 90036
 
Main: 323.330.9900
 
www.worldpokertour.com
 
Confidentiality Notice:  This e-mail transmission (and/or the 
attachments accompanying) it may contain confidential information 
belonging to the sender which is protected.  The information is 
intended only for the use of the intended recipient.  If your are not 
the intended recipient, you are hereby notified that any disclosure, 
copying, distribution or taking of any action in reliance on the 
contents of this information is prohibited. If you have received this 
transmission in error, please notify the sender by reply e-mail and 
destroy all copies of this transmission.

-----Original Message-----
From: Jeff [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 17, 2006 11:54 AM
To: [email protected]
Subject: [PHP] What does a "?" represent

In the some code I'm working with I see many database queries using the
PEAR DB class where  "?" is used for a value in the SQL.  What is the
rule for using "?" in this way what value does it take.

Example code.   

     $ticket=$db->getRow(
            "SELECT id,department,`from`, cc, bcc FROM tickets WHERE
id=?",
            array($tid)
        );

Jeff

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

--- End Message ---
--- Begin Message ---
It's usually used as a single character wildcard.  So "something = ?" would 
match "A", "B", "1", etc..  but not "AB, "A1".

-TG

= = = Original message = = =

In the some code I'm working with I see many database queries using the
PEAR DB class where  "?" is used for a value in the SQL.  What is the
rule for using "?" in this way what value does it take.

Example code.   

     $ticket=$db->getRow(
            "SELECT id,department,`from`, cc, bcc FROM tickets WHERE
id=?",
            array($tid)
        );

Jeff


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--- End Message ---
--- Begin Message --- Not is SQL, the single character wildcard is the underscore. In SQL the ? is usually used for argument replacement, much like the %s in printf.

Satyam

----- Original Message ----- From: <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, February 17, 2006 9:24 PM
Subject: Re: [PHP] What does a "?" represent


It's usually used as a single character wildcard. So "something = ?" would match "A", "B", "1", etc.. but not "AB, "A1".

-TG

= = = Original message = = =

In the some code I'm working with I see many database queries using the
PEAR DB class where  "?" is used for a value in the SQL.  What is the
rule for using "?" in this way what value does it take.

Example code.

    $ticket=$db->getRow(
           "SELECT id,department,`from`, cc, bcc FROM tickets WHERE
id=?",
           array($tid)
       );

Jeff


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Shaunak Kashyap [mailto:[EMAIL PROTECTED] 
> Sent: Friday, February 17, 2006 15:22
> To: [email protected]
> Subject: RE: [PHP] What does a "?" represent
> 
> 
> I'm not sure if these completely answer your question but 
> they might get you started:
> 
> http://dev.mysql.com/doc/refman/4.1/en/mysql-stmt-prepare.html
> http://dev.mysql.com/doc/refman/4.1/en/mysql-stmt-execute.html
> 
> Shaunak Kashyap
>  
> Senior Web Developer
> WPT Enterprises, Inc.
> 5700 Wilshire Blvd., Suite 350
> Los Angeles, CA 90036
>  
> Main: 323.330.9900
>  

Yes, that has the data I needed, thanks!

--- End Message ---
--- Begin Message ---
On Fri, Feb 17, 2006 at 06:48:13PM -0000, Marco Almeida wrote:
> Hi there,
>  
> I'm trying to calculate check digits for a payment system, using the ISO
> 7064 (MOD 97-10) algorithm, wich is, already translated to PHP:
> 
> $check=98-fmod(($num*100),97);
> 
> Where $num is a huge number...
> 
> Example: 90150123123400043211 should have check digit 51
> In windows calculator: 98 - ( (90150123123400043211 * 100) mod 97) works OK
> and I get 51 as result
>
> In PHP I get 13...

You will need to use GMP or BCMath to do math operations numbers
that size.

See:
http://php.net/language.types.integer.php


Curt.
-- 
cat .signature: No such file or directory

--- End Message ---
--- Begin Message ---
I have a following directory:
- folder (site)
   index.php
   - folder (example)
     index.php

the url to this directory will be: http://www.example.com/site/index.php
but I need redirect with: header() function to the index.php inside the folder 
example without the url change
I mean, I want to keep the same url but diferent directory
-- 
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.


--- End Message ---
--- Begin Message ---
If you are in a *nix environment, make a symlink from site_folder/index.php -> 
site_folder/example_folder/index.php and that should do it.

Shaunak Kashyap
 
Senior Web Developer
WPT Enterprises, Inc.
5700 Wilshire Blvd., Suite 350
Los Angeles, CA 90036
 
Main: 323.330.9900
 
www.worldpokertour.com
 
Confidentiality Notice:  This e-mail transmission (and/or the 
attachments accompanying) it may contain confidential information 
belonging to the sender which is protected.  The information is 
intended only for the use of the intended recipient.  If your are not 
the intended recipient, you are hereby notified that any disclosure, 
copying, distribution or taking of any action in reliance on the 
contents of this information is prohibited. If you have received this 
transmission in error, please notify the sender by reply e-mail and 
destroy all copies of this transmission.

-----Original Message-----
From: Jesús Alain Rodríguez Santos [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 17, 2006 2:49 PM
To: [email protected]
Subject: [PHP] URL problem

I have a following directory:
- folder (site)
   index.php
   - folder (example)
     index.php

the url to this directory will be: http://www.example.com/site/index.php
but I need redirect with: header() function to the index.php inside the folder 
example without the url change
I mean, I want to keep the same url but diferent directory
-- 
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.

--- End Message ---
--- Begin Message ---
I figured out that nothing was wrong with this (other than the other things
you pointed out) and that I was just uploading the wrong file to the wrong
place ... oops

Thanks again, Mark 

-----Original Message-----
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 17, 2006 9:24 AM
To: Mark Steudel
Cc: [email protected]
Subject: Re: [PHP] array_map help

Mark Steudel wrote:
> I've got the following code and I am not doing something right. Either 
> my function is wrong, or the way Im using array_map is wrong, as 
> slashes are still making it into the data, and the asdf iosn't getting 
> appended to each value.

I rewrote what you had like so:

<?php
function detectMGQ($value)
{
    //return get_magic_quotes_gpc() ? stripslashes($value): $value;
    return $value."-TEST";
}

$clean = array(
     "name"          => "name",
     "email"         => "email",
     "username"      => "username",
     "accesslevel"   => "accesslevel",
     "status"        => "status",
);

$field_values = array_map( "detectMGQ", $clean ); var_dump($field_values);
?>

and it adds '-TEST' to every value as expected. not sure whats going wrong
with your code exactly by I have got some general comments...
(maybe the code I rewrote helps you to figure otu what was/is going
wrong.)

> 
> Thanks, Mark
> 
> 
> 
> // function to remove stripped slashes function detectMGQ($value) {
>    // Stripslashes
>    if (get_magic_quotes_gpc()) {
>        $value = stripslashes($value);
>    }
>    
>     // added in to detect if this function is working
>    $value .= $value.'asdf';

if $value equals "ABC" then it would equal "ABCABCasdf" aftyer that last
line of code was run.

> 
>    return $value;
> }
> 
> // construct field and value pairs into array
> $field_values =       array(  'name'          => "$clean[name]",
>                                               'email'         =>
> "$clean[email]",

   yuou don't need to wrap $clean[email] in quotes - it's waste of
time+cpu BUT you should always delimit the array key with quotes because
it is a string not a constant (or does you code actually define a constant
named 'email'?) i.e.

"$clean[email]" is better off being $clean['email']

>                                               'username'              =>
> "$clean[username]",
>                                               'accesslevel'   =>
> "$clean[accesslevel]",
>                                               'status'                =>
> "$clean[status]",
>                                               'password'              =>
> base64_encode(rc4($clean[password1])) );
>                       
> 
> // walk through the values and strip out the slashses $field_values = 
> array_map( "detectMGQ", $field_values );
> 

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

--- End Message ---
--- Begin Message ---
Here is how I did it.

<?php

//total days in september
$septNumberOfDays = 30;

//get the day of the month for 12:00:00am on the last day of September of
the current year
$septLastDay = date('w', mktime(0, 0, 0, 9, $septNumberOfDays, date('Y')));

//if the last day itself isn't a sunday
if($septLastDay != 0) {
 //set the last sunday timestamp
 $septLastSunday = mktime(0, 0, 0, 9, ($septNumberOfDays - $septLastDay),
date('Y'));
} else {
 //otherwise set the last sunday timestamp to the last day of sept
 $septLastSunday = mktime(0, 0, 0, 9, $septNumberOfDays, date('Y'));
}

print date('l, F j, Y', $septLastSunday);

?>

"Jay Paulson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I'm building a program and I need to find the last Sunday in September for
> every year because the following Monday is the start of a new year for us.
> So 2006 ends on September 24th 2006 and the new year (2007) starts on
> September 25th 2006.  I was thinking that using the strtotime() would get
> me
> this information possibly?  Is there an easy way to get this information?
>
> Pseudo code:
>
> If ((date > last Sunday in September this year) &&
>    (date < Jan 1 of next year)) {
>    year++
> }

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

I'm having an intermittent problem where the session locks up for some of my 
users.  When the session locks up, the browser just sits there waiting for a 
response from the server.  It seems to be random, which makes it very 
difficult to debug.  It also seems to happen system wide, and not just on a 
particular page (a home-made CRM).  The server is running Apache 2.x and PHP 
4.4.X on RHEL on a quad-processor server with 8 GB RAM.  We do an hourly 
backup that does cause some delays, but the session lockups do not 
necessarily happen around that time.   

Could this be caused by the session garbage collection (we use the default PHP 
sessions), and if it is, what would/could be done to better the situation?

Thanks,
--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
1.800.575.1099

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

I'm having an intermittent problem where the session locks up for some of my 
users.  When the session locks up, the browser just sits there waiting for a 
response from the server.  It seems to be random, which makes it very 
difficult to debug.  It also seems to happen system wide, and not just on a 
particular page (a home-made CRM).  The server is running Apache 2.x and PHP 
4.4.X on RHEL on a quad-processor server with 8 GB RAM.  We do an hourly 
backup that does cause some delays, but the session lockups do not 
necessarily happen around that time.   

Could this be caused by the session garbage collection (we use the default PHP 
sessions), and if it is, what would/could be done to better the situation?

Thanks,
--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
1.800.575.1099

--- End Message ---
--- Begin Message ---
(Don't you hate it when people forget to post back to the list...)

The secret is actually hidden in the docs,
http://php.net/manual/en/language.operators.comparison.php

When comparing $a < $b, you compare the first value of $a (0) to the
value with the same key in $b (1).  0 < 1 --> true

When you compare $b < $a, the first value of $b is 0, with a key of 1.
The value in $a is 1, 0 < 1 --> true

The discussion on php-dev, where you found this example, reveals that
PHP makes the assumption that $a > $b == $b < $a.  This means that they
can reuse the less than function for greater than calls.

In this case the assumption isn't actually valid.  $a > $b should be 0 >
1 --> false.



David

Jochem Maas wrote:
>     THIS CODE
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> php -r '
> $a = array(0, 1);
> $b = array(1 => 0, 0 => 1);
> var_dump($a < $b); // true
> var_dump($a > $b); // true
> var_dump($b < $a);
> var_dump($b > $a);
> 
> echo "\n\$a:\n"; var_dump((bool)$a, (int)$a, (string)$a, intval($a),
> strval($a));
> echo "\n\$b:\n"; var_dump((bool)$b, (int)$b, (string)$b, intval($b),
> strval($b));
> '
> 
>     OUTPUTS (on php5.0.4):
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> bool(true)
> bool(true)
> bool(true)
> bool(true)
> 
> $a:
> bool(true)
> int(1)
> string(5) "Array"
> 
> $b:
> bool(true)
> int(1)
> string(5) "Array"
> 
>     WHICH MEANS THAT:
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> one the one hand $a is greater than AND less than $b
> but on the other hand casting $a OR $b to either a boolean,
> integer or string results in the exact same value. ie:
> 
> php -r '
> $a = array(0, 1); $b = array(1 => 0, 0 => 1);
> var_dump( ((($a > $b) === ($b > $a)) === ((int)$a === (int)$b)) ); //
> WTF IT'S TRUE
> '
> 
> weird? I think so - but then again I'd never test that array $a is
> greater than array $b because this is meaningless to me (in what way is $a
> greater - how is this quantified, what 'rules' determine 'greatness' in
> this context?)
> 
> PS - changing the $b array to something else (anything else as far as i
> can tell)
> causes the weirdness to not occur - which gives me the impression this
> could be a bug,
> anyone else get this impression? for instance try changing the second
> line of
> the code above to (merely switching the order or the defined array
> elements):
> 
> $b = array(0 => 1, 1 => 0);
> 

--- End Message ---
--- Begin Message ---
hi all,
today, i get this error frequently :

A fatal error has occurred
DB Error: extension not found
[line 542 of /var/www/horde/kronolith/lib/Driver/sql.php]
...

but php5-mysql is installed. and also i installed pear db ...
what may cause this problem ? and how can i fix this ?
help please ...
many thanks in advance ...

--- End Message ---
--- Begin Message ---
On 2/16/06, tedd <[EMAIL PROTECTED]> wrote:

> However, after given it some thought, I would imagine that one could
> get a unique generated string, create a file with that string, give
> the file the correct permissions, then pull the image from the dB and
> save, do image processing, and then reload the image into a web page,
> and delete the file without any conflict. I can envision lot's of
> users doing that simultaneously without problems. BUT, I haven't
> tried it yet!

I have used a user's IP address (dots removed) and microtime appended
to create a unique file name. The target directory is world writable.
Not the most elegant solution... I found that sometimes the file had
not been written yet and trying to display it on a page right away
resulted in file not found... Rendering the image to the screen
without saving to a file works best for me.

--
Gerry
http://portal.danen.org/

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

 

I am about to create a feature that will help the visitor in his/her
navigation of the page. I want to store the visitors last 10 pages that was
visited so that this person easily can go back to a page he was at before,
without using the BACK button. I see two solutions to this, but I am not
sure on witch one to choose.

 

1. Create a session variable that contains the last 10 pages and update that
variable for every page he/she visits.

2. Have a database table that contains this information that is related to
the session ID.

 

I am concerned that 2 will take resources from the server, but I would use
an already created link to the database. So maybe the inserts and selects
are neglectable?

 

Number 2 can also be extended to an even better solution, when the user
comes back, the data can be recovered if we set a cookie for this. 

 

However 1 is much easier to implement, but 2 can be extended to better
functionality.

 

Witch one would you choose?

 

/Peter

 

 


--- End Message ---
--- Begin Message ---
On Fri, 2006-02-17 at 23:47, Peter Lauri wrote:
> Hi,
>
> I am about to create a feature that will help the visitor in his/her
> navigation of the page. I want to store the visitors last 10 pages that was
> visited so that this person easily can go back to a page he was at before,
> without using the BACK button. I see two solutions to this, but I am not
> sure on witch one to choose.
>
> 1. Create a session variable that contains the last 10 pages and update that
> variable for every page he/she visits.
> 
> 2. Have a database table that contains this information that is related to
> the session ID.
>
> I am concerned that 2 will take resources from the server, but I would use
> an already created link to the database. So maybe the inserts and selects
> are neglectable?
>
> Number 2 can also be extended to an even better solution, when the user
> comes back, the data can be recovered if we set a cookie for this. 
>
> However 1 is much easier to implement, but 2 can be extended to better
> functionality.
>
> Witch one would you choose?

It's volatile data that you have no desire to keep between sessions
(otherwise you wouldn't link it to the session) in which case unless
there's a LOT of it there's no point using another table -- especially
since it sounds like it will be loaded on every page. If you want
maintainability, use a nice associative array structure that can easily
be adapted later.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Please, answer:

what construction works faster:

   if (  isset ( $result [$i] ["key"] )  )
   {    do something;   }

or

   if (  array_key_exists ( "key", $result [$i] )  )
   {    do something;   }

?

Nikolay

--- End Message ---

Reply via email to