Re: [PHP] exasperated again - shot in the foot

2009-07-01 Thread Stuart
2009/7/1 PJ af.gour...@videotron.ca:
 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



Re: [PHP] exasperated again - shot in the foot

2009-07-01 Thread Lester Caine

Stuart wrote:

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


Of cause it would be nice to see the Bing clockwork toys that run it ...
I couldn't help giggle when they announced they were naming it after a 
toy manuafacturer :)


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] exasperated again - shot in the foot

2009-07-01 Thread Shawn McKenzie
Lester Caine wrote:
 Stuart wrote:
 3) Google/Bing it (yeah, Bing's never gonna catch on like that!)
 
 Of cause it would be nice to see the Bing clockwork toys that run it ...
 I couldn't help giggle when they announced they were naming it after a
 toy manuafacturer :)
 

OT, but the first time I tried bing I resolved to not go back.  If I
search on spidean, which is the name of my site and is a Gaelic word
found in the name of many mountain peaks in Scotland, I get results for
spiderman as top results.  In contrast, google asks me did you mean
spiderman? but gives me all results for spidean.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] exasperated again - shot in the foot

2009-06-30 Thread PJ
PJ wrote:
 Could somebody please explain to me what is wrong with this code?
 In my script it works, returns the correct id, but when I try it in a
 test pages, nothing in the world gets it to work. This is rather
 frustrating, again:
 THIS WORKS IN ANOTHER PAGE; IN THE TEST PAGE ID DOES NOT.
 $sql = SELECT id FROM publishers
 WHERE publisher = 'whoever';
   $result = mysql_query($sql,$db);
 $row = mysql_fetch_assoc($result); 
   if (mysql_num_rows($result) !== 0) {
   $pub = $row['id'];
 Syntax is ok, echo hello; works.


 This works in the test page:
 $aid = array();
 $ord = array();
 $sql = SELECT authID, ordinal
 FROM book_author WHERE bookid = 624 ORDER BY ordinal ASC;
 $result = mysql_query($sql, $db); 
 //$row = mysql_fetch_assoc($result);
 while ( $row = mysql_fetch_assoc($result) ) {
 $aid[]=$row['authID'];
 $ord[]=$row['ordinal'];
 }
 var_dump($aid);
 echo br /;
 var_dump($ord);
 echo $aid[0],  - ;
 echo $ord[0];

 This does not:
 $fi=joe; $la=joe;
 $sql = SELECT id FROM author
 WHERE first_name = '$fi'  last_name = '$la';
 $result = msql_query($sql, $db);
 $row = mysql_fetch_assoc($result);
 $count=mysql_num_rows($result);
 echo $count;
   if (mysql_num_rows($result)  0) {
   $a_id=$row['id'];
   }
   echo $a_id, br /br /;
 The test page prints out echo some text; but no results when the
 results are there
 Tell me I have missed something simple here, or is this normal for php ?
 I have checked the queries on Mysql command line and they are fine.
 I have verified the syntax and Netbeans tells me it is fine.
 Same results Firefox3 (2 machines)  IE 8.
 What is not fine?

   
Damn, it's frustrating to find that there is a difference between msql
and mysql... ouch, the foot hurts now!

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] exasperated again - shot in the foot

2009-06-30 Thread Bastien Koert
On Tue, Jun 30, 2009 at 4:48 PM, PJaf.gour...@videotron.ca wrote:
 PJ wrote:
 Could somebody please explain to me what is wrong with this code?
 In my script it works, returns the correct id, but when I try it in a
 test pages, nothing in the world gets it to work. This is rather
 frustrating, again:
 THIS WORKS IN ANOTHER PAGE; IN THE TEST PAGE ID DOES NOT.
 $sql = SELECT id FROM publishers
         WHERE publisher = 'whoever';
       $result = mysql_query($sql,$db);
         $row = mysql_fetch_assoc($result);
           if (mysql_num_rows($result) !== 0) {
           $pub = $row['id'];
 Syntax is ok, echo hello; works.


 This works in the test page:
 $aid = array();
 $ord = array();
 $sql = SELECT authID, ordinal
         FROM book_author WHERE bookid = 624 ORDER BY ordinal ASC;
         $result = mysql_query($sql, $db);
             //$row = mysql_fetch_assoc($result);
             while ( $row = mysql_fetch_assoc($result) ) {
             $aid[]=$row['authID'];
             $ord[]=$row['ordinal'];
             }
             var_dump($aid);
             echo br /;
             var_dump($ord);
             echo $aid[0],  - ;
             echo $ord[0];

 This does not:
 $fi=joe; $la=joe;
 $sql = SELECT id FROM author
         WHERE first_name = '$fi'  last_name = '$la';
     $result = msql_query($sql, $db);
         $row = mysql_fetch_assoc($result);
         $count=mysql_num_rows($result);
     echo $count;
           if (mysql_num_rows($result)  0) {
           $a_id=$row['id'];
           }
           echo $a_id, br /br /;
 The test page prints out echo some text; but no results when the
 results are there
 Tell me I have missed something simple here, or is this normal for php ?
 I have checked the queries on Mysql command line and they are fine.
 I have verified the syntax and Netbeans tells me it is fine.
 Same results Firefox3 (2 machines)  IE 8.
 What is not fine?


 Damn, it's frustrating to find that there is a difference between msql
 and mysql... ouch, the foot hurts now!

 --
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Blame the native, libraries that is

-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] exasperated again - shot in the foot

2009-06-30 Thread Eddie Drapkin
On Tue, Jun 30, 2009 at 4:50 PM, Bastien Koertphps...@gmail.com wrote:
 On Tue, Jun 30, 2009 at 4:48 PM, PJaf.gour...@videotron.ca wrote:
 PJ wrote:
 Could somebody please explain to me what is wrong with this code?
 In my script it works, returns the correct id, but when I try it in a
 test pages, nothing in the world gets it to work. This is rather
 frustrating, again:
 THIS WORKS IN ANOTHER PAGE; IN THE TEST PAGE ID DOES NOT.
 $sql = SELECT id FROM publishers
         WHERE publisher = 'whoever';
       $result = mysql_query($sql,$db);
         $row = mysql_fetch_assoc($result);
           if (mysql_num_rows($result) !== 0) {
           $pub = $row['id'];
 Syntax is ok, echo hello; works.


 This works in the test page:
 $aid = array();
 $ord = array();
 $sql = SELECT authID, ordinal
         FROM book_author WHERE bookid = 624 ORDER BY ordinal ASC;
         $result = mysql_query($sql, $db);
             //$row = mysql_fetch_assoc($result);
             while ( $row = mysql_fetch_assoc($result) ) {
             $aid[]=$row['authID'];
             $ord[]=$row['ordinal'];
             }
             var_dump($aid);
             echo br /;
             var_dump($ord);
             echo $aid[0],  - ;
             echo $ord[0];

 This does not:
 $fi=joe; $la=joe;
 $sql = SELECT id FROM author
         WHERE first_name = '$fi'  last_name = '$la';
     $result = msql_query($sql, $db);
         $row = mysql_fetch_assoc($result);
         $count=mysql_num_rows($result);
     echo $count;
           if (mysql_num_rows($result)  0) {
           $a_id=$row['id'];
           }
           echo $a_id, br /br /;
 The test page prints out echo some text; but no results when the
 results are there
 Tell me I have missed something simple here, or is this normal for php ?
 I have checked the queries on Mysql command line and they are fine.
 I have verified the syntax and Netbeans tells me it is fine.
 Same results Firefox3 (2 machines)  IE 8.
 What is not fine?


 Damn, it's frustrating to find that there is a difference between msql
 and mysql... ouch, the foot hurts now!

 --
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



 Blame the native, libraries that is

 --

 Bastien

 Cat, the other other white meat

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



Take it as a sign you shouldn't be using mysql_ at all :)

Use the OOP interface to mysqli or PDO and these problems don't happen

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



RE: [PHP] exasperated again - shot in the foot

2009-06-30 Thread Jay Blanchard
[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. 

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



Re: [PHP] exasperated again - shot in the foot

2009-06-30 Thread PJ
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... :-\

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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