Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Paste Description for php mysql_query result problem

why is $res T/F instead of a resource?

php mysql_query result problem
Sunday, April 19th, 2009 at 7:04:02am MDT 

  1. my generalized DB connection function:
  2.  
  3.   function dbopen($mode='read') ## {{{
  4.   {
  5.     require('./localinfo.php') ;
  6.     switch ( $mode )
  7.     {
  8.       case 'read' :     ## {{{
  9.         $dbuser = $db_read_user ;
  10.         $dbpass = $db_read_pass ;
  11.         break ; ## }}}
  12.       case 'write' :    ## {{{
  13.         $dbuser = $db_root_user ;
  14.         $dbpass = $db_root_pass ;
  15.         break ; ## }}}
  16.       default : ## {{{
  17.         die ("Bad db open mode .$mode. ; good bye!") ;
  18.         break ; ## }}}
  19.     }
  20. #    error_reporting(0) ;
  21.     $dblink = mysql_pconnect ($dbhost,$dbuser,$dbpass) ;        ## {{{
  22.     if ( ! $dblink )
  23.       { die("Could not connect to $dbhost : <br/>" . mysql_error()); }
  24.     mysql_select_db ('csrn_mem',$dblink) or die('Could not select DB!') ;
  25.     return $dblink ;    ## }}}
  26.   }     ## }}}
  27.  
  28.  
  29. my query result output in the browser:
  30.  
  31. insert res : 1
  32. qs is
  33. select * from log where l_id = '38428';
  34.  
  35. res : 1
  36.  
  37. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/data/t-g/Logs/tc.php on line 199
  38. Could not fetch select results:
  39.  
  40.  
  41. my php code:
  42.  
  43.     error_reporting(6143) ;     ###
  44.     $dbread = dbopen('write') ;
  45.     $p_id = 1 ; ###
  46.     $qi = "insert into log (entry) values ('sample entry for help');";  ###
  47.     $res = mysql_query($qi,$dbread) || die("Could not insert : ".mysql_error()) ;       ###
  48.     print "insert res : $res<br/>\n" ;  ###
  49.     $qs = "select * from log where l_id = '38428';" ;   ###
  50.     print "qs is <hr/>$qs<hr/>\n" ;     ###
  51.     $res = mysql_query($qs,$dbread) || die('Could not select : '.mysql_error()) ;       ###
  52.     print "res : $res<br/>\n" ; ###
  53.     $dbrows = mysql_fetch_array($res,MYSQL_ASSOC) || die("Could not fetch select results: ".mysql_error()) ;
  54.  
  55.  
  56. my DB contents:
  57.  
  58. mysql> select * from log where l_id = '38428';
  59. +-------+---------------------+----------------------+
  60. | l_id  | stamp               | entry                |
  61. +-------+---------------------+----------------------+
  62. | 38428 | 2009-04-18 23:49:05 | this is a fake entry |
  63. +-------+---------------------+----------------------+
  64. 1 row in set (0.00 sec)

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right