73
73
$ port = DB_PORT ;
74
74
$ user = DB_USER ;
75
75
76
- if (mysqli_connect (
77
- $ server ,
78
- $ user ,
79
- $ pass ,
80
- $ database ,
81
- $ port
82
- )) {
83
- $ db_link = mysqli_connect (
76
+ if ($ db_link = mysqli_connect (
84
77
$ server ,
85
78
$ user ,
86
79
$ pass ,
87
80
$ database ,
88
81
$ port
89
- );
82
+ )
83
+ ) {
84
+ $ db_link ->set_charset (DB_ENCODING );
90
85
} else {
91
86
$ res = 'Impossible to get connected to server. Error is: ' . addslashes (mysqli_connect_error ());
92
87
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: ' . addslashes (mysqli_connect_error ()) . '!"}] ' ;
102
97
// ---->
103
98
// OPERATION - 20230604_1 - generate key for item_key
104
99
100
+ // Start transaction to avoid autocommit
101
+ mysqli_begin_transaction ($ db_link , MYSQLI_TRANS_START_READ_WRITE );
102
+
105
103
// Get items to treat
106
104
$ rows = mysqli_query (
107
105
$ db_link ,
113
111
// Handle error on query
114
112
if (!$ rows ) {
115
113
echo '[{"finish":"1" , "error":" ' .mysqli_error ($ db_link ).'"}] ' ;
114
+ mysqli_commit ($ db_link );
115
+ mysqli_close ($ db_link );
116
116
exit ();
117
117
}
118
118
131
131
);
132
132
if (mysqli_error ($ db_link )) {
133
133
echo '[{"finish":"1", "next":"", "error":"MySQL Error! ' .addslashes (mysqli_error ($ db_link )).'"}] ' ;
134
+ mysqli_commit ($ db_link );
135
+ mysqli_close ($ db_link );
134
136
exit ();
135
137
}
136
138
}
158
160
}
159
161
// Return back
160
162
echo '[{"finish":" ' .$ finish .'" , "next":"", "error":"", "total":" ' .$ total .'"}] ' ;
163
+ // Commit transaction.
164
+ mysqli_commit ($ db_link );
161
165
}
162
166
163
167
164
168
function populateItemsTable_CreatedAt ($ pre , $ post_nb )
165
169
{
166
170
global $ db_link ;
171
+ // Start transaction to avoid autocommit
172
+ mysqli_begin_transaction ($ db_link , MYSQLI_TRANS_START_READ_WRITE );
173
+
167
174
// loop on items - created_at
168
175
$ items = mysqli_query (
169
176
$ db_link ,
@@ -190,12 +197,19 @@ function populateItemsTable_CreatedAt($pre, $post_nb)
190
197
"SELECT * FROM ` " . $ pre . "items` WHERE created_at IS NULL "
191
198
)
192
199
);
200
+
201
+ // Commit transaction.
202
+ mysqli_commit ($ db_link );
203
+
193
204
return $ remainingItems > 0 ? 0 : 1 ;
194
205
}
195
206
196
207
function populateItemsTable_UpdatedAt ($ pre )
197
208
{
198
209
global $ db_link ;
210
+ // Start transaction to avoid autocommit
211
+ mysqli_begin_transaction ($ db_link , MYSQLI_TRANS_START_READ_WRITE );
212
+
199
213
// loop on items - updated_at
200
214
$ items = mysqli_query (
201
215
$ db_link ,
@@ -212,12 +226,18 @@ function populateItemsTable_UpdatedAt($pre)
212
226
}
213
227
}
214
228
229
+ // Commit transaction.
230
+ mysqli_commit ($ db_link );
231
+
215
232
return 1 ;
216
233
}
217
234
218
235
function populateItemsTable_DeletedAt ($ pre )
219
236
{
220
237
global $ db_link ;
238
+ // Start transaction to avoid autocommit
239
+ mysqli_begin_transaction ($ db_link , MYSQLI_TRANS_START_READ_WRITE );
240
+
221
241
// loop on items - deleted_at
222
242
$ items = mysqli_query (
223
243
$ db_link ,
@@ -234,6 +254,9 @@ function populateItemsTable_DeletedAt($pre)
234
254
}
235
255
}
236
256
257
+ // Commit transaction.
258
+ mysqli_commit ($ db_link );
259
+
237
260
return 1 ;
238
261
}
239
262
@@ -273,6 +296,9 @@ function installPurgeUnnecessaryKeys(bool $allUsers = true, int $user_id=0, stri
273
296
function installPurgeUnnecessaryKeysForUser (int $ user_id =0 , string $ pre )
274
297
{
275
298
global $ db_link ;
299
+ // Start transaction to avoid autocommit
300
+ mysqli_begin_transaction ($ db_link , MYSQLI_TRANS_START_READ_WRITE );
301
+
276
302
if ($ user_id === 0 ) {
277
303
return ;
278
304
}
@@ -319,6 +345,9 @@ function installPurgeUnnecessaryKeysForUser(int $user_id=0, string $pre)
319
345
WHERE object_id IN ( ' .$ pfItemsList .') AND user_id NOT IN ( ' .TP_USER_ID .', ' .$ user_id .') '
320
346
);
321
347
}
348
+
349
+ // Commit transaction.
350
+ mysqli_commit ($ db_link );
322
351
}
323
352
324
353
0 commit comments