Mysql_affected_rows returns false on a successful query?

I am having a difficult time sorting through this PHP/MySQL issue. Let me show you my database, and explain my situation:

Create table:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(50) NOT NULL AUTO_INCREMENT,
  `active` varchar(20) NOT NULL,
  `activation` varchar(15) NOT NULL,
  `firstName` longtext NOT NULL,
  `lastName` longtext NOT NULL,
  `passWord` longtext NOT NULL,
  `changePassword` text NOT NULL,
  `emailAddress1` longtext NOT NULL,
  `emailAddress2` longtext NOT NULL,
  `emailAddress3` longtext NOT NULL,
  `role` longtext NOT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `name` (`firstName`,`lastName`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

Insert a value:

INSERT INTO `users` (
  `id` ,
  `active` ,
  `activation` ,
  `firstName` ,
  `lastName` ,
  `passWord` ,
  `changePassword` ,
  `emailAddress1` ,
  `emailAddress2` ,
  `emailAddress3` ,
  `role`
) VALUES (
  NULL,  '1000000000',  'abcdefghijklmno',  'John',  'Smith',  '*24D7FB97963C40FE5C56A6672F9560FC8B681508',  'on',  '[email protected]',  '',  '',  'User'
);

Update a value:

$affected = mysql_query(UPDATE users SET passWord = PASSWORD('a9eb42e1b3be829ef42972ea9abab334'), changePassword = 'on' WHERE emailAddress1 = '[email protected]', $dbID); 

if (mysql_affected_rows($affected)) {
    //Never runs
}

The above UPDATE
query executes just fine in my script, phpMyAdmin, and the MySQL terminal. However, mysql_affected_rows($affected)
always
gives me this error:

Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given

I know that this means my query failed, but every time I go into the database, I see that the values have been updated.

Removing the parameter from the function appears to clear things up. However, I rather have the identifier as the function parameter, just to be sure what I am referring to, and for code insurance.

Any idea why this might be doing this?

Thank you for your time.

http://php.net/mysql_query

Return Values

For other type of SQL statements, INSERT
, UPDATE
, DELETE
, DROP
, etc, mysql_query()
returns TRUE
on success or FALSE
on error.

And:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )

This means mysql_affected_rows
wants a mysql connection resource as an argument. Not the result of mysql_query
, and most certainly not if that result is only true
or false
. You use it like this:

$successful = mysql_query('UPDATE ...'); 

if ($successful) {
    echo 'Affected rows: ' . mysql_affected_rows();
} else {
    echo 'Fail: ' . mysql_error();
}
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Mysql_affected_rows returns false on a successful query?

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录