![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I created website using PHP5+MySQL. It contains 3 pages: 1. enter_announcement.php - enter/change real estate announcement 2. submit_announcement.php - add/modify announcement in database 3. summary.php - show summary information. To be precise: the page enter_announcement.php submits to submit_announcement.php which redirects (at the end) to summary.php. Announcement number consist of 3 parts: year, month, sequential number in month. Here is draft of submit_announcement.php: START TRANSACTION LOCK TABLES announcements WRITE if (empty($_POST['full_announcement_no'])) { // new announcement $announcement = new Announcement; $announcement->initializeWithPOST(); INSERT INTO announcements with new number MAX+1 } else { // change announcement $announcement = new Announcement; $announcement->initializeWithPOST(); $announcement->initializeWithNumber($_POST['full_announcement_no'])); UPDATE announcements } UNLOCK TABLES COMMIT header('Location: summary.php'); The problem is that I am not sure if inside transaction the command LOCK TABLES is necessary. I lock announcements table because of concurrency (many users) of announcement number generation (SELECT MAX(no)+1 FROM announcements WHERE year=current AND month=current). Please help. Thanks in advance. |
#3
| |||
| |||
|
|
Just use an auto_increment column and don't worry about MAX+1. *Then you don't need to lock tables. |
#4
| |||
| |||
|
|
Just use an auto_increment column and don't worry about MAX+1. ?Then you don't need to lock tables. I cannot use auto increment because announcement number consist of 3 parts: year, month, sequential number within month. After month changes I need to start new sequence. |
#5
| |||
| |||
|
|
Hello, I created website using PHP5+MySQL. It contains 3 pages: 1. enter_announcement.php - enter/change real estate announcement 2. submit_announcement.php - add/modify announcement in database 3. summary.php - show summary information. To be precise: the page enter_announcement.php submits to submit_announcement.php which redirects (at the end) to summary.php. Announcement number consist of 3 parts: year, month, sequential number in month. Here is draft of submit_announcement.php: START TRANSACTION LOCK TABLES announcements WRITE if (empty($_POST['full_announcement_no'])) { // new announcement $announcement = new Announcement; $announcement->initializeWithPOST(); INSERT INTO announcements with new number MAX+1 } else { // change announcement $announcement = new Announcement; $announcement->initializeWithPOST(); $announcement->initializeWithNumber($_POST['full_announcement_no'])); UPDATE announcements } UNLOCK TABLES COMMIT header('Location: summary.php'); The problem is that I am not sure if inside transaction the command LOCK TABLES is necessary. I lock announcements table because of concurrency (many users) of announcement number generation (SELECT MAX(no)+1 FROM announcements WHERE year=current AND month=current). |
![]() |
| Thread Tools | |
| Display Modes | |
| |