Re: invalid resource for fetch_object??

From: Date: Wed, 30 Apr 2003 18:31:25 +0000
Subject: Re: invalid resource for fetch_object??
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-145835@lists.php.net to get a copy of this message
> > > mysql_query("select count(*) from prayer"); > > $total=mysql_affected_rows(); > > > also i get only 1 records found when it sends me mail about what the script > > had done and found when i know there are 5 records in the table?? > > $total contains the affected rows which is meaningless given that your query > is a COUNT(*). You can either: > > SELECT * FROM prayer; then use mysql_num_rows() > > OR > > SELECT COUNT(*) FROM prayer; then use mysql_fetch_array() and get the value > of the first element. > > that failed because of an error with version differences in mysql... in 3.22.1 count(*) only returns 1 row because thats the only row being shown.. i should have done : $result=mysql_query(select * from prayer"); $total=mysql_affected_rows($total); > > > $status1=mysql_query("select version() as version, connection_id() as > > connection, now() as time, benchmark(1, \"delete from prayer where Posted > > <= now()-interval 14 day\") as bench"); > > > on the $status1= line it takes the version number time and all that sort of > > stuff and then does a query for a delete from a table it then takes the > > select on the $status1 line and tries to do a fetch_object on the select > > but for some reason i get a invalid resource for that function?? how come > > when i can do the work manual but the php script says that? > > Assign your query to a variable. echo() that variable to ensure that the query > looks OK and copy & paste that into the mysql commandline to see whether it > works. Error check what's being returned from mysql_query() and use > mysql_error(). again i found out that mysql 3.22.1 doesnt support connection_id() and it doesnt support now() -interval or now() +interval.. have to use date_sub(curdate(), interval 14 day) instead as far as the mysql_error goes i should have added that but was a draft script and now i have to rewrite the whole thing anyways... > > > would fetchJ_array or fetch_row be better for that? > These return different things so you really can't compare them. fetch_object and fetch_array didnt work because $status1= line failed > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > ------------------------------------------ > Search the list archives before you post > http://marc.theaimsgroup.com/?l=php-general > ------------------------------------------ > /* > Using TSO is like kicking a dead whale down the beach. > -- S.C. Johnson > */ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#145835) next »