note 52889 added to function.mysql-affected-rows

From: Date: Tue, 17 May 2005 00:57:20 +0000
Subject: note 52889 added to function.mysql-affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-89511@lists.php.net to get a copy of this message
I am a general user of PHP and Mysql, not an expert. But I am having following problem: we have two tables called Users(uID, uName) Users_Groups (gID, uID, isAdmin) uID is Autoincreament in Users and Foreign key in UserGroups table. I am using transactions to insert a new user into User Table and immediately insert into Users_Groups during the same transaction. It is an atomic operation. This happens in the same PHP script. I tried using use mysqli and old mysql_ calls. This transcation works well when I execute in an IDE like mysqlControl Center. But in the PHP script. It does not go through Here is the PHP Pseudocde Begin SET FOREIGN_KEY_CHECKS = 0 Insert into Users Table If (sucessful) Then Retrieve userid = mysql_insert_id Insert into Users_Groups values(gID, userid, 0) if (sucessful) Then COMMIT else ROLLBACK SET FOREIGN_KEY_CHECKS = 1 In this case I am able to retrieve and print the inserted mysql_insert_id for Users table but when I try to insert it into the Users_Groups table it fails and ROLLS-BACK. My guess is it fails the Foreign key constraint even though I SET FOREIGN_KEY_CHECKS = 0. Any ideas why this may be happening? Please let me know. Thank you in advance, Abhi ---- Manual Page -- http://www.php.net/manual/en/function.mysql-affected-rows.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52889 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52889&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52889&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52889&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52889&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52889&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52889&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89511) next »