forked from jimjag/mysql-wrapper
/
mysql-wrapper.php
605 lines (512 loc) · 24.4 KB
/
mysql-wrapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<?php
# mysql to mysqli migration library
# by dotpointer
# changelog
# 2013-09-24 - first version
# 2013-09-25 - updated with is_mysql_resource() and bugfixes
# 2013-09-26 19:23 - adding some more function wrappers
# 2013-10-24 23:16:41 - bugfix, mysql_connect used invalid error functions
# 2013-11-11 - updated mysql_result() contributed by marc17 (GitHub)
# 2014-02-16 - updated mysql_result() contributed by marc17 (GitHub)
# BEWARE, mysql constants are directly translated to mysqli, so the actual value may differ
# BEWARE, those are made to sql queries - please inspect: create_db, drop_db
# BEWARE, mysql_escape_string now takes the last used connection
## RENAMED: mysql-wrapper.php
# to check if an item is a resource/object - replace is_resource with this
function is_mysql_resource($result)
{
# first try to treat as resource if original mysql is loaded
if (extension_loaded('mysql')) {
return is_resource($result);
}
# or if mysqli is loaded, try to check object
if (extension_loaded('mysqli')) {
return is_object($result);
}
die('Fatal error, mysqli extension not loaded.');
}
# only do this is mysql extension is not there
if (!extension_loaded('mysql')) {
# check if mysqli extension is loaded - its required as we rely on it
if (!extension_loaded('mysqli')) {
die('Fatal error, mysqli extension not loaded.');
}
# --- helper variables and constants ---------------------------------------------------------------------------------------------------
# a list of connections, used to get the last one
$mysql_links = array();
# our own constants to reach default connection values in INI file
define('MYSQL_DEFAULT_HOST', ini_get("mysql.default_host"));
define('MYSQL_DEFAULT_USER', ini_get("mysql.default_user"));
define('MYSQL_DEFAULT_PASSWORD', ini_get("mysql.default_password"));
# --- MySQL constants (from PHP.net) ---------------------------------------------------------------------------------------------------
# MySQL client constants
define('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS); # Use compression protocol
define('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE); # Allow space after function names
define('MYSQL_CLIENT_INTERACTIVE', MYSQLI_CLIENT_INTERACTIVE); # Allow interactive_timeout seconds
# (instead of wait_timeout ) of
# inactivity before closing the connection.
define('MYSQL_CLIENT_SSL', MYSQLI_CLIENT_SSL); # Use SSL encryption. This flag is only
# available with version 4.x of the MySQL
# client library or newer. Version 3.23.x is
# bundled both with PHP 4 and Windows binaries
# of PHP 5.
# mysql_fetch_array() uses a constant for the different types of result arrays. The following constants are defined:
# MySQL fetch constants
define('MYSQL_ASSOC', MYSQLI_ASSOC); # Columns are returned into the array having
# the fieldname as the array index.
define('MYSQL_BOTH', MYSQLI_BOTH); # Columns are returned into the array having
# both a numerical index and the fieldname as
# the array index.
define('MYSQL_NUM', MYSQLI_NUM); # Columns are returned into the array having a
# numerical index to the fields. This index
# starts with 0, the first field in the result.
# --- helper functions ---------------------------------------------------------------------------------------------------
# lib helper function - to ensure mysql link as mysqli always needs one
# but mysql takes last one
function mysql_ensure_link($link_identifier)
{
# no link specified
if ($link_identifier === NULL) {
global $mysql_links;
# no connection at all - then go null
if (!count($mysql_links)) {
return NULL;
}
# get the last item of the array
$last = end($mysql_links);
# return the last stored link
return $last['link'];
}
return $link_identifier;
}
# --- MySQL functions (from PHP.net) ---------------------------------------------------------------------------------------------------
# mysql_affected_rows - Get number of affected rows in previous MySQL operation
# int mysql_affected_rows ([ resource $link_identifier = NULL ] )
# int mysqli_affected_rows ( mysqli $link )
function mysql_affected_rows($link_identifier = null)
{
return mysqli_affected_rows(mysql_ensure_link($link_identifier));
}
# mysql_client_encoding - Returns the name of the character set
# string mysql_client_encoding ([ resource $link_identifier = NULL ] )
# mysqli_character_set_name ( mysqli $link )
function mysql_client_encoding($link_identifier = null)
{
# note that mysqlI_client_encoding ALSO is deprecated, so we cannot use that
return mysqli_character_set_name(mysql_ensure_link($link_identifier));
}
# mysql_close - Close MySQL connection
# bool mysql_close ([ resource $link_identifier = NULL ] )
# bool mysqli_close ( mysqli $link )
function mysql_close($link = null)
{
global $mysql_links;
$link = mysql_ensure_link($link);
$thread_id = isset($link->thread_id) && is_numeric($link->thread_id) ? $link->thread_id : false;
$result = mysqli_close($link);
# did the removal suceed and and we have thread id
if ($result && $thread_id) {
# walk the links
foreach ($mysql_links as $k => $v) {
# does this thread-id match the one we just removed?
if ($v['thread_id'] === $thread_id) {
# then remove it from connection array
array_splice($mysql_links, $k, 1);
break;
}
}
}
}
# mysql_connect - Open a connection to a MySQL Server
# resource mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] )
# mysqli mysqli_connect ([ string $host = ini_get("mysqli.default_host") [, string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
function mysql_connect($server = MYSQL_DEFAULT_HOST, $username = MYSQL_DEFAULT_USER, $password = MYSQL_DEFAULT_PASSWORD, $new_link = false, $client_flags = 0)
{
global $mysql_links;
# no newlink but s/u/p matches prev ones-take last link
if (!$new_link) {
global $mysql_links;
# are there prev links?
if (count($mysql_links)) {
# get the last one made
$last = end($mysql_links);
# does the s/u/p match last one?
if ($server === $last['server'] && $username === $last['username'] && $password === $last['password'] && is_resource($last['link'])) {
# then take that
return mysql_ensure_link(null);
}
}
}
# try to connect using current credentials
$link = mysqli_connect($server, $username, $password, "");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}
# store this
$mysql_links[] = array(
'thread_id' => $link->thread_id,
'server' => $server,
'username' => $username,
'password' => $password,
'link' => $link,
);
return $link;
}
# mysql_create_db - Create a MySQL database
# bool mysql_create_db ( string $database_name [, resource $link_identifier = NULL ] )
# CREATE DATABASE
function mysql_create_db($database_name, $link_identifier = null)
{
return mysql_query('CREATE DATABASE "'.mysql_real_escape_string($database_name).'"', $link_identifier);
}
# mysql_data_seek - Move internal result pointer
# bool mysql_data_seek ( resource $result , int $row_number )
# bool mysqli_data_seek ( mysqli_result $result , int $offset )
function mysql_data_seek($result, $row_number)
{
return mysqli_data_seek($result, $row_number);
}
# mysql_db_name - Retrieves database name from the call to # mysql_list_dbs
# string mysql_db_name ( resource $result , int $row [, mixed $field = NULL ] )
# SELECT DATABASE()
#function mysql_db_name($result , $row, $field = NULL) {
# return mysql_query('SELECT DATABASE()', mysql_ensure_link($link_identifier));
#}
# mysql_db_query - Selects a database and executes a query on it
# resource mysql_db_query ( string $database , string $query [, resource $link_identifier = NULL ] )
# mysqli_select_db() then the query
function mysql_db_query($database, $query, $link_identifier = null)
{
mysql_select_db($database, $link_identifier);
return mysql_query($query, $link_identifier);
}
# mysql_drop_db - Drop (delete) a MySQL database
# bool mysql_drop_db ( string $database_name [, resource $link_identifier = NULL ] )
# DROP DATABASE
function mysql_drop_db($database_name, $link_identifier = null)
{
return mysql_query('DROP DATABASE "'.mysql_real_escape_string($database_name).'"', $link_identifier);
}
# mysql_errno -Returns the numerical value of the error message from previous MySQL operation
# int mysql_errno ([ resource $link_identifier = NULL ] )
# int mysqli_errno ( mysqli $link )
function mysql_errno($link_identifier = null)
{
return mysqli_errno(mysql_ensure_link($link_identifier));
}
# mysql_error - Returns the text of the error message from previous MySQL operation
# string mysql_error ([ resource $link_identifier = NULL ] )
# string mysqli_error ( mysqli $link )
function mysql_error($link_identifier = null)
{
return mysqli_error(mysql_ensure_link($link_identifier));
}
# mysql_escape_string - Escapes a string for use in a # mysql_query
# string mysql_escape_string ( string $unescaped_string )
# string mysqli::real_escape_string ( string $escapestr )
function mysql_escape_string($unescaped_string)
{
return mysql_real_escape_string($unescaped_string);
}
# mysql_fetch_array - Fetch a result row as an associative array, a numeric array, or both
# array mysql_fetch_array ( resource $result [, int $result_type = MYSQL_BOTH ] )
# mixed mysqli_fetch_array ( mysqli_result $result [, int $resulttype = MYSQLI_BOTH ] )
function mysql_fetch_array($result, $result_type = MYSQL_BOTH)
{
return mysqli_fetch_array($result, $result_type);
}
# mysql_fetch_assoc - Fetch a result row as an associative array
# array mysql_fetch_assoc ( resource $result )
# array mysqli_fetch_assoc ( mysqli_result $result )
function mysql_fetch_assoc($result)
{
return mysqli_fetch_assoc($result);
}
# mysql_fetch_field - Get column information from a result and return as an object
# object mysql_fetch_field ( resource $result [, int $field_offset = 0 ] )
# object mysqli_fetch_field ( mysqli_result $result ) - but field_offset is missing
function mysql_fetch_field($result, $field_offset = null)
{
# if field offset is specified
if (is_numeric($field_offset)) {
# then seek to that
mysqli_field_seek($result, $field_offset);
}
return mysqli_fetch_field($result);
}
# mysql_fetch_lengths - Get the length of each output in a result
# array mysql_fetch_lengths ( resource $result )
# array mysqli_fetch_lengths ( mysqli_result $result )
function mysql_fetch_lengths($result)
{
return mysqli_fetch_lengths($result);
}
# mysql_fetch_object - Fetch a result row as an object
# object mysql_fetch_object ( resource $result [, string $class_name [, array $params ]] )
# object mysqli_fetch_object ( mysqli_result $result [, string $class_name [, array $params ]] )
function mysql_fetch_object($result, $class_name = null, $params = null)
{
if ($class_name !== NULL && $params !== NULL) {
return mysqli_fetch_object($result, $class_name, $params);
} elseif ($class_name !== NULL) {
return mysqli_fetch_object($result, $class_name);
}
return mysqli_fetch_object($result);
}
# mysql_fetch_row - Get a result row as an enumerated array
# array mysql_fetch_row ( resource $result )
# mixed mysqli_fetch_row ( mysqli_result $result )
function mysql_fetch_row($result)
{
return mysqli_fetch_row($result);
}
# mysql_field_flags - Get the flags associated with the specified field in a result
# string mysql_field_flags ( resource $result , int $field_offset )
# mysqli_fetch_field_direct() [flags]
# -> object mysqli_fetch_field_direct ( mysqli_result $result , int $fieldnr )
function mysql_field_flags($result, $field_offset)
{
$tmp = mysqli_fetch_field_direct($result, $field_offset);
if (!is_object($tmp)) {
return false;
}
$tmp = (array) $tmp;
return isset($tmp['flags']) ? $tmp['flags'] : false;
}
# mysql_field_len - Returns the length of the specified field
# int mysql_field_len ( resource $result , int $field_offset )
# mysqli_fetch_field_direct() [length]
# -> object mysqli_fetch_field_direct ( mysqli_result $result , int $fieldnr )
function mysql_field_len($result, $field_offset)
{
$tmp = mysqli_fetch_field_direct($result, $field_offset);
if (!is_object($tmp)) {
return false;
}
$tmp = (array) $tmp;
return isset($tmp['length']) ? $tmp['length'] : false;
}
# mysql_field_name - Get the name of the specified field in a result
# string mysql_field_name ( resource $result , int $field_offset )
# mysqli_fetch_field_direct() [name] or [orgname]
# -> object mysqli_fetch_field_direct ( mysqli_result $result , int $fieldnr )
function mysql_field_name($result, $field_offset)
{
$tmp = mysqli_fetch_field_direct($result, $field_offset);
if (!is_object($tmp)) {
return false;
}
$tmp = (array) $tmp;
return isset($tmp['name']) ? $tmp['name'] : false;
}
# mysql_field_seek - Set result pointer to a specified field offset
# bool mysql_field_seek ( resource $result , int $field_offset )
# bool mysqli_field_seek ( mysqli_result $result , int $fieldnr )
function mysql_field_seek($result, $field_offset)
{
return mysqli_field_seek($result, $field_offset);
}
# mysql_field_table - Get name of the table the specified field is in
# string mysql_field_table ( resource $result , int $field_offset )
# mysqli_fetch_field_direct() [table] or [orgtable]
# -> object mysqli_fetch_field_direct ( mysqli_result $result , int $fieldnr )
function mysql_field_table($result, $field_offset)
{
$tmp = mysqli_fetch_field_direct($result, $field_offset);
if (!is_object($tmp)) {
return false;
}
$tmp = (array) $tmp;
return isset($tmp['table']) ? $tmp['table'] : false;
}
# mysql_field_type - Get the type of the specified field in a result
# string mysql_field_type ( resource $result , int $field_offset )
# mysqli_fetch_field_direct() [type]
# -> object mysqli_fetch_field_direct ( mysqli_result $result , int $fieldnr )
function mysql_field_type($result, $field_offset)
{
$tmp = mysqli_fetch_field_direct($result, $field_offset);
if (!is_object($tmp)) {
return false;
}
$tmp = (array) $tmp;
return isset($tmp['type']) ? $tmp['type'] : false;
}
# mysql_free_result - Free result memory
# bool mysql_free_result ( resource $result )
# void mysqli_free_result ( mysqli_result $result )
function mysql_free_result($result)
{
mysqli_free_result($result);
# note that mysqli does not return any boolean, so we do it
return true;
}
# mysql_get_client_info - Get MySQL client info
# string mysql_get_client_info ( void )
# string mysqli_get_client_info ( mysqli $link )
function mysql_get_client_info()
{
# note that mysql does not have a link argument while mysqli does
return mysqli_get_client_info(mysql_ensure_link());
}
# mysql_get_host_info - Get MySQL host info
# string mysql_get_host_info ([ resource $link_identifier = NULL ] )
# string mysqli_get_host_info ( mysqli $link )
function mysql_get_host_info($link_identifier = null)
{
return mysqli_get_host_info(mysql_ensure_link($link_identifier));
}
# mysql_get_proto_info - Get MySQL protocol info
# int mysql_get_proto_info ([ resource $link_identifier = NULL ] )
# int mysqli_get_proto_info ( mysqli $link )
function mysql_get_proto_info($link_identifier = null)
{
return mysqli_get_proto_info(mysql_ensure_link($link_identifier));
}
# mysql_get_server_info - Get MySQL server info
# string mysql_get_server_info ([ resource $link_identifier = NULL ] )
# string mysqli_get_server_info ( mysqli $link )
function mysql_get_server_info($link_identifier = null)
{
return mysqli_get_server_info(mysql_ensure_link($link_identifier));
}
# mysql_info - Get information about the most recent query
# string mysql_info ([ resource $link_identifier = NULL ] )
# string mysqli_info ( mysqli $link )
function mysql_info($link_identifier = null)
{
return mysqli_info(mysql_ensure_link($link_identifier));
}
# mysql_insert_id - Get the ID generated in the last query
# int mysql_insert_id ([ resource $link_identifier = NULL ] )
# mixed mysqli_insert_id ( mysqli $link )
function mysql_insert_id($link_identifier = null)
{
return mysqli_insert_id(mysql_ensure_link($link_identifier));
}
# mysql_list_dbs - List databases available on a MySQL server
# resource mysql_list_dbs ([ resource $link_identifier = NULL ] )
# SQL Query: SHOW DATABASES
function mysql_list_dbs($link_identifier = null)
{
return mysql_query('SHOW DATABASES', mysql_ensure_link($link_identifier));
}
# mysql_list_fields - List MySQL table fields
# resource mysql_list_fields ( string $database_name , string $table_name [, resource $link_identifier = NULL ] )
# SQL Query: SHOW COLUMNS FROM sometable
function mysql_list_fields($database_name, $table_name, $link_identifier = null)
{
return mysql_query('SHOW COLUMNS FROM "'.mysql_real_escape_string($database_name).'.'.mysql_real_escape_string($table_name).'"', mysql_ensure_link($link_identifier));
}
# mysql_list_processes - List MySQL processes
# resource mysql_list_processes ([ resource $link_identifier = NULL ] )
# mysqli_thread_id()
function mysql_list_processes($link_identifier = null)
{
return mysqli_thread_id(mysql_ensure_link($link_identifier));
}
# mysql_list_tables - List tables in a MySQL database
# resource mysql_list_tables ( string $database [, resource $link_identifier = NULL ] )
# SQL Query: SHOW TABLES FROM sometable
function mysql_list_tables($database_name, $table_name, $link_identifier = null)
{
return mysql_query('SHOW TABLES FROM "'.mysql_real_escape_string($database_name).'"', mysql_ensure_link($link_identifier));
}
# mysql_num_fields - Get number of fields in result
# int mysql_num_fields ( resource $result )
# int mysqli_field_count ( mysqli $link )
function mysql_num_fields($result)
{
# mysql takes a result, where mysqli takes link and takes the most recent query
# so instead we fetch all the fields and then count that
$tmp = mysqli_fetch_fields($result);
if ($tmp === false) {
return false;
}
return count($tmp);
}
# mysql_num_rows - Get number of rows in result
# int mysql_num_rows ( resource $result )
# int mysqli_num_rows ( mysqli_result $result )
function mysql_num_rows($result)
{
return mysqli_num_rows($result);
}
# mysql_pconnect - Open a persistent connection to a MySQL server
# resource mysql_pconnect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, int $client_flags = 0 ]]]] )
# mysqli_connect() with p: host prefix
function mysql_pconnect($server = MYSQL_DEFAULT_HOST, $username = MYSQL_DEFAULT_USER, $password = MYSQL_DEFAULT_PASSWORD, $client_flags = 0)
{
return mysql_connect('p:'.$server, $username, $password, true, $client_flags);
}
# mysql_ping - Ping a server connection or reconnect if there is no connection
# bool mysql_ping ([ resource $link_identifier = NULL ] )
# bool mysqli_ping ( mysqli $link )
function mysql_ping($link_identifier = null)
{
return mysqli_ping(mysql_ensure_link($link_identifier));
}
# mysql_query - Send a MySQL query
# resource mysql_query ( string $query [, resource $link_identifier = NULL ] )
# mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
function mysql_query($query, $link_identifier = null)
{
return mysqli_query(mysql_ensure_link($link_identifier), $query);
}
# mysql_real_escape_string - Escapes special characters in a string for use in an SQL statement
# string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier = NULL ] )
# string mysqli_real_escape_string ( mysqli $link , string $escapestr )
function mysql_real_escape_string($unescaped_string, $link_identifier = null)
{
return mysqli_real_escape_string(mysql_ensure_link($link_identifier), $unescaped_string);
}
# mysql_result - Get result data
# string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )
# no equivalent function exists in mysqli - mysqli_data_seek() in conjunction with mysqli_field_seek() and mysqli_fetch_field()
function mysql_result($result, $row, $field = 0)
{
# try to seek position
if (mysqli_data_seek($result, $row) === false) {
return false;
}
$row = mysqli_fetch_array($result);
if (!isset($row[$field])) {
return false;
}
return $row[$field];
}
# mysql_select_db - Select a MySQL database
# bool mysql_select_db ( string $database_name [, resource $link_identifier = NULL ] )
function mysql_select_db($database_name, $link_identifier = null)
{
return mysqli_select_db(mysql_ensure_link($link_identifier), $database_name);
}
# mysql_set_charset - Sets the client character set
# bool mysql_set_charset ( string $charset [, resource $link_identifier = NULL ] )
# bool mysqli_set_charset ( mysqli $link , string $charset )
function mysql_set_charset($charset, $link_identifier = null)
{
return mysqli_set_charset(mysql_ensure_link($link_identifier), $charset);
}
# mysql_stat - Get current system status
# string mysql_stat ([ resource $link_identifier = NULL ] )
# string mysqli_stat ( mysqli $link )
function mysql_stat($link_identifier = null)
{
return mysqli_stat(mysql_ensure_link($link_identifier));
}
# mysql_tablename - Get table name of field
# string mysql_tablename ( resource $result , int $i )
# no mysqli equivalent exists - SHOW TABLES [FROM db_name] [LIKE 'pattern']
#function mysql_tablename ($result, $i) {
# return mysql_query('SHOW COLUMNS FROM "'.mysql_real_escape_string($database_name).'.'.mysql_real_escape_string($table_name).'"', mysql_ensure_link($link_identifier));
#}
# mysql_thread_id - Return the current thread ID
# int mysql_thread_id ([ resource $link_identifier = NULL ] )
# int mysqli_thread_id ( mysqli $link )
function mysql_thread_id($link_identifier = null)
{
return mysqli_thread_id(mysql_ensure_link($link_identifier));
}
}