Re: exasperated again - shot in the foot

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

 



2009/7/1 PJ <af.gourmet@xxxxxxxxxxxx>:
> Jay Blanchard wrote:
>> [snip]
>> Use the OOP interface to mysqli or PDO and these problems don't happen
>> [/snip]
>>
>> Either that or include a modicum of error checking in your code.
>>
>>
> OK, Ok, I feel stupid enough already.
> I'm not sure I want to get in that deep... it's tough enough with the
> simple stuff...
> so, talk to me about the OOP interface or the PDO... :-\

The first step on the road to enlightenment is to learn how to learn
without asking for help.

1) RTFM

2) Try it - set up a sandbox where you can play with code and make
mistakes without consequences

3) Google/Bing it (yeah, Bing's never gonna catch on like that!)

4) Try it again

5) If you're still having problems ask here and include evidence that
you've put some effort into steps 1-4

This list should be your last port of call when you can't figure something out.

Now I have to disagree that the OO variants of the MySQL API are any
better than the plain old mysql_* functions. In particular I have
found PDO to be significantly slower. Yes you have to take care of
escaping values in SQL statements yourself, but having to be
consciously aware of security issues is never a bad thing unless
you're lazy about it.

As Jay says you cannot assume that any code that calls external
services is going to work. You need to check return values, catch
exceptions and do everything else you can to handle unexpected events.
I've found that 99.99% of the time MySQL is perfectly reliable, but in
the 0.01% you may unexpectedly lose the connection for any number of
reasons. If you don't handle it then you could end up losing data but
happily telling your users it was stored successfully.

In general this is known as defensive programming. Never assume
anything, handle every eventuality you can think of including the
"this will never happen" cases, and always make sure you have a
catch-all for stuff you can't think of. Learn to do this early and
you'll have a much better time of it.

Now I have to go and find June - I'm sure I lost a few days in there somewhere.

-Stuart

-- 
http://stut.net/

-- 
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