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
- my generalized DB connection function:
- function dbopen($mode='read') ## {{{
- {
- require('./localinfo.php') ;
- switch ( $mode )
- {
- case 'read' : ## {{{
- $dbuser = $db_read_user ;
- $dbpass = $db_read_pass ;
- break ; ## }}}
- case 'write' : ## {{{
- $dbuser = $db_root_user ;
- $dbpass = $db_root_pass ;
- break ; ## }}}
- default : ## {{{
- die ("Bad db open mode .$mode. ; good bye!") ;
- break ; ## }}}
- }
- # error_reporting(0) ;
- $dblink = mysql_pconnect ($dbhost,$dbuser,$dbpass) ; ## {{{
- if ( ! $dblink )
- { die("Could not connect to $dbhost : <br/>" . mysql_error()); }
- mysql_select_db ('csrn_mem',$dblink) or die('Could not select DB!') ;
- return $dblink ; ## }}}
- } ## }}}
- my query result output in the browser:
- insert res : 1
- qs is
- select * from log where l_id = '38428';
- res : 1
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/data/t-g/Logs/tc.php on line 199
- Could not fetch select results:
- my php code:
- error_reporting(6143) ; ###
- $dbread = dbopen('write') ;
- $p_id = 1 ; ###
- $qi = "insert into log (entry) values ('sample entry for help');"; ###
- $res = mysql_query($qi,$dbread) || die("Could not insert : ".mysql_error()) ; ###
- print "insert res : $res<br/>\n" ; ###
- $qs = "select * from log where l_id = '38428';" ; ###
- print "qs is <hr/>$qs<hr/>\n" ; ###
- $res = mysql_query($qs,$dbread) || die('Could not select : '.mysql_error()) ; ###
- print "res : $res<br/>\n" ; ###
- $dbrows = mysql_fetch_array($res,MYSQL_ASSOC) || die("Could not fetch select results: ".mysql_error()) ;
- my DB contents:
- mysql> select * from log where l_id = '38428';
- +-------+---------------------+----------------------+
- | l_id | stamp | entry |
- +-------+---------------------+----------------------+
- | 38428 | 2009-04-18 23:49:05 | this is a fake entry |
- +-------+---------------------+----------------------+
- 1 row in set (0.00 sec)
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.
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.