Re: "use strict" or similar in PHP?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hans Schultz wrote:

> Is there in PHP something like "use strict" from perl? I find it pretty
> annoying to need to run script over and over again just to find out that I
> made typo in variable name.

I find that my IDE catches most of the typos before I even try to run the page.
I use Netbeans 6.5 with the PHP extension, but there are alternatives...

> Is there some way for PHP to cache some data on the page? I like very much
> PHP's speed but it would be even better to be able to cache some frequently
> used data from database?

Generally it's not worth the trouble, but you could cache in the session...
Remember that PHP is largely stateless, so one page call knows nothing of any
other page calls. This is different to Java, where you can hold state in the
underlying virtual machine and recover it later...

> Also regarding databases, I liked a lot java's way of sending data to
> database
> using parameters ("select * from user where username = ?" and then passing
> parameter separately with database doing necessary escaping and
> everything).
> Is there something like PHPDBC similar to JDBC?

With PostgreSQL (and probably MySQL too) you can do either a prepared statement
(see http://www.php.net/manual/en/function.pg-prepare.php) and then execute
that, or a simpler parameterised query (see
http://www.php.net/manual/en/function.pg-query-params.php)
Something like

$sql = 'SELECT * FROM user WHERE username=$1';
$params = Array('pete');
$result = pg_query_params($sql,$params);

That way you get the safest handling of values without any tedious messing about
with manually escaping strings.
I suspect that under the hood it actually prepares a statement and then executes
it, but I might be wrong...


-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux