anatak Posted July 18, 2006 Share Posted July 18, 2006 Topic is solvedI had a database connection that was not closed correctly and that gave me this problemHey I am running a query that updates the read status of a mail when clickedexample.UPDATE mail SET MailRead = '0' WHERE MailId = '1269';I check if the update is done using this function.[code]FUNCTION update_1_row_check($arg1){ $Query = $arg1; echo $Query; if ((mysql_query($Query) == 1) && (mysql_affected_rows() == 1)) { $result = "TRUE"; } else { $result = "<BR> there was a problem updating the information <br />please contact the administrator with the following message: "; $result = $result . "<BR>mysql db query: " . mysql_query($Query); $result = $result . "<BR>mysql affected rows: " . mysql_affected_rows(); } //echo "result in db.inc= ".$result; return($result);}[/code]I think the SQL is correct because when I select a row that will be updated by clicking on the mail I see that the readstatus is 1 (not read)and after clicking on the mail I see that the readstatus is changed to 0.The problem is that mysql_affected_rows() returns 0 even when the status is changed.This problem occured after changing hosting.I am really clueless here. Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/ Share on other sites More sharing options...
redarrow Posted July 18, 2006 Share Posted July 18, 2006 Wheres the code to update the database ok. Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-59978 Share on other sites More sharing options...
hitman6003 Posted July 18, 2006 Share Posted July 18, 2006 You probably need to supply the mysql connection resource variable to the mysql_affected_rows function:[code]mysql_affected_rows($connectionresource)[/code]The manual says it's not required, but if you are having problems, it's worth trying. Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-59991 Share on other sites More sharing options...
anatak Posted July 18, 2006 Author Share Posted July 18, 2006 [quote author=hitman6003 link=topic=101002.msg399295#msg399295 date=1153243539]You probably need to supply the mysql connection resource variable to the mysql_affected_rows function:[code]mysql_affected_rows($connectionresource)[/code]The manual says it's not required, but if you are having problems, it's worth trying.[/quote]do you mean like this ?[code]FUNCTION update_1_row_check($arg1){ $Query = $arg1; echo $Query; $Result = mysql_query($Query) or die(mysql_error()); if ((mysql_affected_rows($Result) == 1) { $result = "TRUE"; } else { $result = "<BR> there was a problem updating the information <br />please contact the administrator with the following message: "; $result = $result . "<BR>mysql db query: " . mysql_query($Query); $result = $result . "<BR>mysql affected rows: " . mysql_affected_rows(); } //echo "result in db.inc= ".$result; return($result);}[/code]This results in the following errorWarning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource inif ((mysql_affected_rows() == 1)does not give the error but I still have the same problem in that mysql_affected_rows() returns 0 instead of 1;The thing that is really getting me is that this works without problem on my local machine but has a problem on the server.Somebody any ideas ?maybe a difference in phpversion or mysqlversion between the testing (ofline) and online environment ?any help is greatly appreciatedanatak Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-60207 Share on other sites More sharing options...
hitman6003 Posted July 18, 2006 Share Posted July 18, 2006 Result is the result of the query. When you establish the connection to the database it should be assigned to a variable:[code]$connection = mysql_connect(...);[/code]The $connection is what you want to supply to the function. Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-60211 Share on other sites More sharing options...
akitchin Posted July 19, 2006 Share Posted July 19, 2006 you'll want to fix your if() statement as well:[code]if ((mysql_affected_rows($Result) == 1)[/code]that's missing a closing parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-60292 Share on other sites More sharing options...
anatak Posted July 19, 2006 Author Share Posted July 19, 2006 [code]well this is really freaking me out.The function works with other update statements and the database gets updated alright.it is just that with this update statement for some reason the number of affected rows is returned 0and it gets even weirder.I just reset all the mails in my inbox to unread status and when I read some mails sometimes I get the error and sometimes not.I begin to suspect that maybe a database connection is not closed somewhere and that the mysql_affected_rows is getting information from a different connection.Does this sound possible ?ok I keep looking for it and now I got an error for my closing of a database connection.[code[function read_connection(){//guest connection (read only)$GLOBALS["ReadConnection"] = mysql_connect($GLOBALS["Host"], $GLOBALS["SelectUser"], $GLOBALS["SelectPassword"]);if (!$GLOBALS["SelectPassword"]) die ("Could not connect MySQL guestconnection: " . mysql_errno() . " : " . mysql_error());//database selecteren en connectie openenmysql_select_db($GLOBALS["Database"],$GLOBALS["ReadConnection"]) or die ("Could not open database guestconnection: " . mysql_errno() . " : " . mysql_error());mysql_query("SET NAMES 'utf8'");}//END READ CONNECTIE OPENEN//START READ ONLY CONNECTION SLUITENfunction read_close(){ mysql_close($GLOBALS["ReadConnection"]);}[/code]apparantly there is something wrong with the mysql_close($GLOBALS["ReadConnection"]);I get this errorWarning: mysql_close(): 63 is not a valid MySQL-Link resource in db.inc on line 88does anybody sees the fault ?anatak Quote Link to comment https://forums.phpfreaks.com/topic/14948-solved-mysql_affected_rows-problem/#findComment-60379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.