Possible Duplicate:
MySQL AUTO_INCREMENT does not ROLLBACK
<?php
header("Content-Type:text/html; charset=utf-8") ;
$conn = mysql_connect('127.0.0.1', 'root', '123456') ;
mysql_select_db('test') ;
mysql_query('set autocommit=0') ;
mysql_query('start transaction') ;
try
{
$sql = "insert into `user`(`username`, `password`) values('demo', 'demopassword')" ;
echo $sql, '<br/>' ;
$rs = mysql_query($sql) ;
echo mysql_affected_rows(), '<br/>' ;
if (mysql_affected_rows() > 0)
{
$uid = mysql_insert_id() ;
echo $uid, '<br/>' ;
throw new Exception('conn exception : ' . mysql_error()) ;
}
else
{
throw new Exception('conn exception : ' . mysql_error()) ;
}
}
catch(Exception $e)
{
echo $e->getMessage(), '<br/>' ;
echo "rollback", "<br/>" ;
mysql_query('rollback') or die(mysql_error()) ;
}
if (!$conn)
{
mysql_close($conn) ;
}
?>
sorry .. my english is so poor...
see above codes... when I fresh that page ... uid variable will auto increment .. why?
i hope u understand me... please help..thanks