php-general Digest 19 Jan 2010 15:12:03 -0000 Issue 6546
Topics (messages 301202 through 301216):
Re: integrating shipping with shopping cart site - OT
301202 by: Jochem Maas
64 bit date in 32 bit php ??
301203 by: Michael A. Peters
301209 by: Ashley Sheridan
301213 by: Richard Quadling
Re: Casting objects.
301204 by: Richard Quadling
Cookies & sessions
301205 by: clancy_1.cybec.com.au
301206 by: Bruno Fajardo
301207 by: kranthi
301208 by: Richard
301212 by: Phpster
Re: 64 Bit IIS 6 ( 32 Bit mode ) + 32Bit php connect with MS-SQL Server
301210 by: Richard Quadling
301211 by: Richard Quadling
301214 by: Edward S.P. Leong
301215 by: Richard Quadling
Object Oriented Programming question
301216 by: Ben Stones
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 ---
Op 1/18/10 10:47 AM, Angelo Zanetti schreef:
> Hi all,
>
> We are about to start a new project. Custom written shopping cart - quite
> simple actually. However we have a concern when it comes to calculating the
> shipping cost for an order.
>
> For each product we can determine the base cost based on weight, therefore
> we can determine the total weight of an order.
>
> However we are struggling to determine how to calculate the shipping based
> on where the delivery is going.
>
> In terms of DB and PHP would the best way to calculate it be done by having
> a list of countries to ship to and a rate for each? Then you can apply the
> rate to the current order (calculate according to the order weight).
>
> Problems arise when shipping to different parts of a country EG:
>
> New York vs California (quite far apart). Perhaps we should have a list of
> cities but that could be massive?
>
> I know there is a PHP class / system that integrates with UPS but I don't
> think the client is going to use UPS.
>
> Perhaps you can tell me how you have handled this issue in the past.
>
> Apologies if it is slightly off topic but it does still relate to PHP
> indirectly.
I'd start with defining shippingcost 'sets', each defining a number of
costs by weight bands, some 'table defs':
set:
---------
id name
set_bands:
----------
set_id upper_weight cost
then it would be a case of linking (many-to-many relation) 'regions' to sets,
if you approach this with a tree of regions you can effectively set values at
a continent, country, state/province level ... as such you would only need to
relate a 'shippingcostset' to a state if the shippingcosts are different to
the given country's shippingcosts.
world
- north america
- california
- south america
- europe
- france
- UK
then your left with the problem of determining the smallest defined region a
given
address physically falls into .. using geo-spatial magic in the DB would be one
way to do it.
this is a hard problem (unless, maybe, the client is willing to sacrifice
precision
and instead using highly averaged shipping cost definitions to cover the real
differences
in costs - i.e. a fixed fee for all of europe, whereby such fee is just above
the
average real cost the client pays for shipping).
my guess would be that building such a thing is hard, and would take lots of
time ... best bet is to hook into the webservice of whatever shipping company
the
client intends to use ... even if you have to build your end of the webservice
from
scratch it will be many factors less hard that building a user-manageable,
shipping cost
algorythm.
- sorry it's all a bit vague, I'm very tired :) my eyes are starting to bleed.
>
> Thanks in advance.
> Angelo
>
>
> http://www.wapit.co.za
> http://www.elemental.co.za
>
>
>
--- End Message ---
--- Begin Message ---
php 5.2.12 running in CentOS 5.x
Unfortunately, both my server (xen linode) and my test server (crappy
old dell I found in a field) are 32-bit. I need to work with some dates
earlier than 1901 and I would really prefer to store them in *nix time
in the database and use the date() function to format them for display
when I need to.
My understanding is that 32 bit php has a lower limit in 1901 and upper
limit in 2038 for the date function.
Is there a pcre / pecl / other wrapper that behaves identical to the
date function but uses a 64 bit float in 32 bit php?
Yes, the right thing to do is probably to use 64 bit, and if I could I
would. A wrapper that just passes it off to date on 64 bit systems and
to date on 32 bit systems within what data can handle and only does its
magic on 32 bit systems with values beyond 32-bit date capabilities
would be sweet.
--- End Message ---
--- Begin Message ---
On Mon, 2010-01-18 at 22:46 -0800, Michael A. Peters wrote:
> php 5.2.12 running in CentOS 5.x
>
> Unfortunately, both my server (xen linode) and my test server (crappy
> old dell I found in a field) are 32-bit. I need to work with some dates
> earlier than 1901 and I would really prefer to store them in *nix time
> in the database and use the date() function to format them for display
> when I need to.
>
> My understanding is that 32 bit php has a lower limit in 1901 and upper
> limit in 2038 for the date function.
>
> Is there a pcre / pecl / other wrapper that behaves identical to the
> date function but uses a 64 bit float in 32 bit php?
>
> Yes, the right thing to do is probably to use 64 bit, and if I could I
> would. A wrapper that just passes it off to date on 64 bit systems and
> to date on 32 bit systems within what data can handle and only does its
> magic on 32 bit systems with values beyond 32-bit date capabilities
> would be sweet.
>
I've not used it, but the Pear Date class looks like it should do what
you need. I've used other Pear classes before, and they are pretty easy
to get to grips with, so I assume it should be the same for this one
too.
http://pear.php.net/package/Date
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
2010/1/19 Ashley Sheridan <[email protected]>:
> On Mon, 2010-01-18 at 22:46 -0800, Michael A. Peters wrote:
>
>> php 5.2.12 running in CentOS 5.x
>>
>> Unfortunately, both my server (xen linode) and my test server (crappy
>> old dell I found in a field) are 32-bit. I need to work with some dates
>> earlier than 1901 and I would really prefer to store them in *nix time
>> in the database and use the date() function to format them for display
>> when I need to.
>>
>> My understanding is that 32 bit php has a lower limit in 1901 and upper
>> limit in 2038 for the date function.
>>
>> Is there a pcre / pecl / other wrapper that behaves identical to the
>> date function but uses a 64 bit float in 32 bit php?
>>
>> Yes, the right thing to do is probably to use 64 bit, and if I could I
>> would. A wrapper that just passes it off to date on 64 bit systems and
>> to date on 32 bit systems within what data can handle and only does its
>> magic on 32 bit systems with values beyond 32-bit date capabilities
>> would be sweet.
>>
>
>
> I've not used it, but the Pear Date class looks like it should do what
> you need. I've used other Pear classes before, and they are pretty easy
> to get to grips with, so I assume it should be the same for this one
> too.
>
> http://pear.php.net/package/Date
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
php -r "$o = new DateTime('1066-10-14T14:30:00+0000'); echo $o->format('r');"
Battle of Hastings. Just after 2:30 on the 14th of October 1066.
As I understand things, the DateTime class avoids the 32bit issue entirely.
Take a listen to the excellent PHP|Architect Summer Web cast from last
year by Derick Rethans [1] & [2].
Regards,
Richard.
[1] http://phparch.com/webcasts
[2] http://mtadata.s3.amazonaws.com/webcasts/20090828-date-time.wmv
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
2010/1/18 Shawn McKenzie <[email protected]>:
> Shawn McKenzie wrote:
>>>
>> Never mind, that was stupid. I saw that somewhere before, but obviously
>> it doesn't work.
>>
>
> I found some code, maybe I redeem myself?
>
> static public function cast(&$object, $class=__CLASS__){
>
> if(class_exists($class)) {
> $object = unserialize(
> preg_replace('/^O:[0-9]+:"[^"]+":/i',
> 'O:'.strlen($class).':"'.$class.'":',
> serialize($object)));
> }
> }
>
> $row = odbc_fetch_object($result);
> structuresRemovalReason::cast($row);
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
That's an interesting approach.
Though I'm going to use reflection. I realise I need to hold some of
the data in strings where the data is not a string (datetimes for
example).
So, using a docblock with a customtag and this seems to be working just fine.
Extended ReflectionClass and ReflectionProperty.
Thanks,
Richard.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
I am trying for the first time to use cookies. The manual contains the
statement "Cookies
are part of the HTTP header, so setcookie() must be called before any output is
sent to
the browser."
When I first started using sessions, I was alarmed to read a very similar
statement about
sessions, but I soon found that if I started my program with the statement
"session_start();" I could then set up, access, modify or clear any session
variable at
any time in my program. This is enormously useful, as I can put the session
handling at
any convenient point in my program, and can precede them with diagnostics if I
need to.
However I have almost immediately found that while I appear to be able to read
cookies at
any time, I cannot set them when I would like to. Is there any similar trick
which will
work with cookies? If I really have to work out what they should be, and then
set them up,
before issuing any diagnostics, etc, it will make life decidely more
complicated. (I
assume that I can set several cookies using successive calls to setcookie()?)
I was also somewhat surprised to find that a cookie is used to implement
sessions. Does
this place any limitations on using both sessions and cookies in the same
program?
--- End Message ---
--- Begin Message ---
2010/1/19 <[email protected]>:
> I am trying for the first time to use cookies. The manual contains the
> statement "Cookies
> are part of the HTTP header, so setcookie() must be called before any output
> is sent to
> the browser."
>
> When I first started using sessions, I was alarmed to read a very similar
> statement about
> sessions, but I soon found that if I started my program with the statement
> "session_start();" I could then set up, access, modify or clear any session
> variable at
> any time in my program. This is enormously useful, as I can put the session
> handling at
> any convenient point in my program, and can precede them with diagnostics if
> I need to.
>
> However I have almost immediately found that while I appear to be able to
> read cookies at
> any time, I cannot set them when I would like to. Is there any similar trick
> which will
> work with cookies?
The only trick is that you have to call setcookie() before any output
is sent to the browser, just like the session_start() behavior.
> If I really have to work out what they should be, and then set them up,
> before issuing any diagnostics, etc, it will make life decidely more
> complicated. (I
> assume that I can set several cookies using successive calls to setcookie()?)
Yes, each one with a differente name.
>
> I was also somewhat surprised to find that a cookie is used to implement
> sessions. Does
> this place any limitations on using both sessions and cookies in the same
> program?
>
No. The cookie in PHP that implements session is by default called
PHPSESSID. As long as your other cookies are named differently, you
should be fine.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
> When I first started using sessions, I was alarmed to read a very similar
> statement about
> sessions, but I soon found that if I started my program with the statement
> "session_start();" I could then set up, access, modify or clear any session
> variable at
> any time in my program. This is enormously useful, as I can put the session
> handling at
> any convenient point in my program, and can precede them with diagnostics if
> I need to.
are you looking for ob_* functions ?
--- End Message ---
--- Begin Message ---
Hi,
> However I have almost immediately found that while I appear to be able to
> read cookies at
> any time, I cannot set them when I would like to. Is there any similar trick
> which will
> work with cookies?
Keep in mind that cookies are set by sending an HTTP header as part of
the response, so until you do that they can't be sent back to you by
the client (and subsequently appear in $_COOKIE).
> (I assume that I can set several cookies using successive calls to
> setcookie()?)
Sure. Not that I've done it.
> I was also somewhat surprised to find that a cookie is used to implement
> sessions. Does
> this place any limitations on using both sessions and cookies in the same
> program?
No (give them a different name though). You can also use sessions by
putting the session ID on the URL, but this, I believe, is called "a
ball ache".
--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 16th January)
Follow me on Twitter: http://twitter.com/_rgraph
Lots of PHP and Javascript code - http://www.phpguru.org
--- End Message ---
--- Begin Message ---
Be aware that there is a limit of 20 cookies per domain
Bastien
Sent from my iPod
On Jan 19, 2010, at 6:12 AM, Bruno Fajardo <[email protected]> wrote:
2010/1/19 <[email protected]>:
I am trying for the first time to use cookies. The manual contains
the statement "Cookies
are part of the HTTP header, so setcookie() must be called before
any output is sent to
the browser."
When I first started using sessions, I was alarmed to read a very
similar statement about
sessions, but I soon found that if I started my program with the
statement
"session_start();" I could then set up, access, modify or clear any
session variable at
any time in my program. This is enormously useful, as I can put the
session handling at
any convenient point in my program, and can precede them with
diagnostics if I need to.
However I have almost immediately found that while I appear to be
able to read cookies at
any time, I cannot set them when I would like to. Is there any
similar trick which will
work with cookies?
The only trick is that you have to call setcookie() before any output
is sent to the browser, just like the session_start() behavior.
If I really have to work out what they should be, and then set them
up,
before issuing any diagnostics, etc, it will make life decidely
more complicated. (I
assume that I can set several cookies using successive calls to
setcookie()?)
Yes, each one with a differente name.
I was also somewhat surprised to find that a cookie is used to
implement sessions. Does
this place any limitations on using both sessions and cookies in
the same program?
No. The cookie in PHP that implements session is by default called
PHPSESSID. As long as your other cookies are named differently, you
should be fine.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
2010/1/19 <[email protected]>:
> 引述 Richard Quadling <[email protected]>:
>
>> 1 - Can you confirm that the ini file you are editing is the one that
>> is reported in phpinfo() as the file being used?
>
> Yes, BUT there is no MSSQL info of it...
>
>> 2 - At a command prompt, change directory to your PHP installation and
>> type ...
>>
>> php -m
>>
>> See if you have any errors being reported.
>>
>> If the INI file is in an unusual location, then use ...
>>
>> php -c <location_of_php.ini file> -m
>
> T:\php5>php -c t:\php5\php.ini -m
> PHP Warning: PHP Startup: Unable to load dynamic library
> 'T:\PHP5\ext\php_mssql
> .dll' - The specified module could not be found.
> in Unknown on line 0
> [PHP Modules]
> bcmath
> calendar
> com_dotnet
> ctype
> date
> dom
> filter
> ftp
> gd
> hash
> iconv
> json
> libxml
> mbstring
> mcrypt
> mysql
> odbc
> pcre
> Reflection
> session
> SimpleXML
> SPL
> standard
> tokenizer
> wddx
> xml
> xmlreader
> xmlwriter
> zlib
>
> [Zend Modules]
>
> T:\php5\ext>dir php_mssql.dll
> Volume in drive T is Data
> Volume Serial Number is DC85-706F
>
> Directory of T:\php5\ext
>
> 2009/12/16 下午 05:06 49,232 php_mssql.dll
> 1 File(s) 49,232 bytes
> 0 Dir(s) 52,215,365,632 bytes free
>
> T:\php5\ext>
>
> BTW : when running the cli of php -c t:\php5\php.ini -m, the system prompt
> me there is no "MSVCR71.dll" found...
> So, how can I install the dll file for test ( php -m ) again ?
>
> Thanks !
>
> Edward.
>
>
>
>
>
> ----------------------------------------------------------------
> ITA Web Site : http://www.ita.org.mo
> E-mail Address : [email protected]
>
>
It seems you are missing one (or more) of the MS Visual C Runtime files.
http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
is where I'd go next.
But, first, I'd confirm this issue.
If you have depends.exe (http://www.dependencywalker.com/) to open the
php_mssql.dll and see if it reports the missing file in the same way -
look at the bottom of the bottom panel.
Whilst PHP _can_ find the php_mssql.dll file, it is unable to load it
due to missing libraries required by the dll.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
But having said all of that, the php_mssql.dll uses a very old library
which may give you issues.
For the time being, using ODBC (php_odbc is built in for PHP on
Windows) is a much safer solution. You can also use the latest SQL
Native Client driver so you can talk to SQL7, 2000, 2005, 2008.
If you are used to using a DNS-less connection, then ...
$Conn = odbc_pconnect("Driver={SQL Server Native Client
10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
$User, $Password, SQL_CUR_USE_DRIVER);
will give you the connection without the need to have a DNS entry.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
Richard Quadling wrote:
>But having said all of that, the php_mssql.dll uses a very old library
>which may give you issues.
>
>For the time being, using ODBC (php_odbc is built in for PHP on
>Windows) is a much safer solution. You can also use the latest SQL
>Native Client driver so you can talk to SQL7, 2000, 2005, 2008.
>
>If you are used to using a DNS-less connection, then ...
>
>$Conn = odbc_pconnect("Driver={SQL Server Native Client
>10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
>$User, $Password, SQL_CUR_USE_DRIVER);
>
>will give you the connection without the need to have a DNS entry.
>
>
Hello to you,
Where can we download the SQL Native Client driver for talking to MS-SQL
( eg : 2000 ) ?
Thanks !
--- End Message ---
--- Begin Message ---
2010/1/19 Edward S.P. Leong <[email protected]>:
> Richard Quadling wrote:
>
>>But having said all of that, the php_mssql.dll uses a very old library
>>which may give you issues.
>>
>>For the time being, using ODBC (php_odbc is built in for PHP on
>>Windows) is a much safer solution. You can also use the latest SQL
>>Native Client driver so you can talk to SQL7, 2000, 2005, 2008.
>>
>>If you are used to using a DNS-less connection, then ...
>>
>>$Conn = odbc_pconnect("Driver={SQL Server Native Client
>>10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
>>$User, $Password, SQL_CUR_USE_DRIVER);
>>
>>will give you the connection without the need to have a DNS entry.
>>
>>
> Hello to you,
>
> Where can we download the SQL Native Client driver for talking to MS-SQL
> ( eg : 2000 ) ?
>
> Thanks !
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en
and you also have the option of an official MS SQL driver for PHP
http://www.codeplex.com/SQLSRVPHP
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
Hi,
I've been learning about object oriented programming for the past few weeks
and I've understood it pretty well, but I have one question. Usually with
PHP scripts I make, all the functionality for a specific page is in the
actual PHP file, and I'd use PHP functions in a separate directory which
would be included in whichever PHP file needs specific functions I have
created. The functions would be for the specific things in my script, such
as validation checks, functionality that will be used/repeated a lot
throughout my script, etc. What I don't understand about OOP is what its
primary purpose is for. Do I use OOP for all the functionality of my
application, in separate directories, and include these specific class files
and call the methods to complete specific functionality needed for whatever
PHP file I'm working on, or is OOP used for specific functionality like I
would with functions? Essentially what I'm asking is what is the primary
purpose for OOP? Hope you understand.
Thanks,
--- End Message ---