Re: php mysql result problem



davidtg wrote:
Hi, all --

On Apr 19, 9:04 am, davidtg <thorgu...@xxxxxxxxx> wrote:
...
Surf over tohttp://pastebin.ca/1396445to see the examples described
below.

Now it's below in this post.


...
still have no idea why this $res is a T/F instead of a resource.

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)


TIA & HAND

:-D
--
David T-G
See http://justpickone.org/davidtg/email/

First of all, why are you using mysql_pconnect()? This is only really good in about the top 0.05% of the busiest webservers in the world - the rest of the time it can cause more problems than it resolves. You should be using mysql_connect() instead.

As to your problem: you got a valid result back, but there were no rows in the the result set. This is normal when no data is found.

I suspect the data is not found because you are searching a numeric column for string data ('38248'). But I'm surprised you didn't get a SQL error on this.

One other point - don't use die(). It abnormally terminates processing of the page immediately after the message is sent to the client. This means if you have any footers, menus, etc. which are sent after this, they will not be. Rather, if the request fails, you display your own error message and continue processing with what you can.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: php mysql result problem
    ... Jerry Stuckle wrote: ... But I'm surprised you didn't get a SQL error on this. ... It abnormally terminates processing of the page immediately after the message is sent to the client. ... Rather, if the request fails, you display your own error message and continue processing with what you can. ...
    (comp.lang.php)
  • Re: mySQL error handling with PERL
    ... > I need to provide a user friendly error message for SQL errors besides messages like this: ... CGI script dies. ... If you do not want the program to terminate on an SQL error, ... Please read `perldoc DBI` (or visit ...
    (comp.lang.perl.misc)
  • Re: how to write a recursive function?
    ... now I have the following error message when I type fwin the command window: ... At compilation "fw" was determined to be variable. ... If it is res, then why call ...
    (comp.soft-sys.matlab)
  • Re: Error after code is run
    ... Set LookupRange = ... res = Application.VLookup(frm_InputTM.txt_PrtNumber.Value, ... Look at your Workbook Before_Close code in the ... | the end when i want to close it, i get an error message "Run-Time error ...
    (microsoft.public.excel.programming)
  • Re: sed: backreference in substitution does not work as expected
    ... > Could some friendly soul tell me why ... > causes the error message ... Because you have no referent for "\1". ... REs, if you wish parentheses to be metacharacters, ...
    (comp.unix.shell)