2024.8.23
Loading...
Searching...
No Matches
db_common.inc.php File Reference

Go to the source code of this file.

Functions

 db_close_database ()
 
 db_create_database ($database, $server="", $username="", $password="")
 
 db_create_field ($tablename, $field, $type)
 
 db_create_record ($tablename, $fieldnames=null, $fieldvalues=null, $idfield="id")
 
 db_create_table ($tablename, $fieldnames, $fieldattrib, $idfield="id", $valarray=null)
 
 db_delete_field ($tablename, $field)
 
 db_delete_records ($tablename, $idarray, $idfield="id")
 
 db_delete_table ($tablename)
 
 db_edit_field ($tablename, $field, $type)
 
 db_edit_record ($tablename, $id=0, $fieldnames=null, $fieldvalues=null, $idfield="id")
 
 db_escape_string ($str)
 
 db_fetch_array ($result, $type=FETCH_NUM)
 
 db_free_result ($result)
 
 db_get_data ($tablename, $id=null, $col=null, $where="", $result_type=FETCH_NUM, $idfield="id", $orderby="")
 
 db_get_id ($tablename, $index, $idfield="id")
 
 db_get_index ($tablename, $id, $idfield="id")
 
 db_get_info ($info="")
 
 db_get_next_free_id ($tablename, $idfield="id")
 
 db_list_database_tables ()
 
 db_list_table_fields ($tablename, $type=false)
 
 db_open_database ($database, $server="", $username="", $password="")
 
 db_query ($query)
 
 db_rename_field ($tablename, $field, $newname, $type)
 
 db_rename_table ($tablename, $newname)
 
 db_swap_records ($tablename, $id1, $id2, $idfield="id", $xchangeid=true)
 
 db_table_exists ($tablename)
 

Variables

 $_mainpath = pathinfo(__FILE__)
 
const DB_WRAPVERSION "db_v2b"
 
 if (!defined("APPPREFIX")) define("APPPREFIX"
 

Function Documentation

◆ db_close_database()

db_close_database ( )

db_close_database()

Returns
bool "TRUE" or "FALSE"

Definition at line 113 of file db_common.inc.php.

114{
115 return raw_db_close_database();
116}
raw_db_close_database()

References raw_db_close_database().

◆ db_create_database()

db_create_database ( $database,
$server = "",
$username = "",
$password = "" )

db_create_database() Creates a database if it does not exist

Parameters
$database
string$server
string$username
string$password
Returns
resource or "FALSE"

Definition at line 77 of file db_common.inc.php.

78{
79 return raw_db_create_database($database, $server, $username , $password);
80}
raw_db_create_database($database, $server="", $username="", $password="")

References raw_db_create_database().

◆ db_create_field()

db_create_field ( $tablename,
$field,
$type )

db_create_field()

Parameters
$tablename
$field
$type
Returns
bool "TRUE" or "FALSE"

Definition at line 248 of file db_common.inc.php.

249{
250 return raw_db_create_field(APPPREFIX . $tablename, $field, $type);
251}
raw_db_create_field($tablename, $field, $type)

References raw_db_create_field().

◆ db_create_record()

db_create_record ( $tablename,
$fieldnames = null,
$fieldvalues = null,
$idfield = "id" )

db_create_record()

Insert a new record in table $tablename.

Parameters
$tablenameTable name. If NULL uses the table used in last function call.
unknown$fieldnamesArray or CSV string with field names, one per line.
unknown$fieldvaluesArray or CSV string with field values, one per line.
string$idfield
Returns
id of the affected record, FALSE if not succeded

Definition at line 304 of file db_common.inc.php.

305{
306 global $g_lasttable;
307
308 if (!$tablename)
309 $tablename = $g_lasttable;
310 $g_lasttable = $tablename;
311
312 if (!$fieldnames) {
313 $fieldnames = db_list_table_fields($tablename);
314 array_shift($fieldnames);
315 }
316 if (!$fieldvalues) {
317 $fieldvalues = array_fill(0, count($fieldnames), 0);
318
319 }
320 // Get next available index
321 $sql = "SELECT max($idfield) FROM " . APPPREFIX . $tablename;
322 $result = raw_db_query($sql);
323 if ($result === false) {
324 return false;
325 }
326 $newid = (db_fetch_array($result, FETCH_NUM)) ;
327 $newid = $newid[0] + 1;
328 // Build the two arrays
329 $names = is_string($fieldnames) ? preg_split("/[\r\n]/", $fieldnames) : $fieldnames;
330 $values = is_string($fieldvalues) ? preg_split("/[\r\n]/", $fieldvalues) : $fieldvalues;
331 if (count($names) != count($values)) {
332 trigger_error(__FUNCTION__ . ": both arrays must be same length.\n");
333 return false;
334 }
335 // Build the SQL query
336 $nfields = count($names);
337 $fieldnames = $names;
338 $fieldvalues = $values;
339 for($i = 0, $names = ""; $i < $nfields; $i++)
340 $names .= $fieldnames[$i] . ($i < $nfields - 1 ? ", " : "");
341 for($i = 0, $values = ""; $i < $nfields; $i++)
342 $values .= "'" . db_escape_string($fieldvalues[$i]) . "'" . ($i < $nfields - 1 ? ", " : "");
343
344 $sql = "INSERT INTO " . APPPREFIX . $tablename . " ($idfield, $names) VALUES ($newid, $values)";
345
346 $result = raw_db_query($sql);
347 if (!$result) {
348 trigger_error(__FUNCTION__ . ": could not create new record in table $tablename.");
349 return false;
350 }
351 return $newid;
352}
$result
db_escape_string($str)
db_list_table_fields($tablename, $type=false)
db_fetch_array($result, $type=FETCH_NUM)
const FETCH_NUM
raw_db_query($query)

References $result, db_escape_string(), db_fetch_array(), db_list_table_fields(), FETCH_NUM, and raw_db_query().

Referenced by db_create_table(), and db_edit_record().

+ Here is the caller graph for this function:

◆ db_create_table()

db_create_table ( $tablename,
$fieldnames,
$fieldattrib,
$idfield = "id",
$valarray = null )

db_create_table()

Parameters
$tablename
$fieldnames( beside "id" )
$fieldattrib
string$idfield( set to "id" )
array$valarray( $valarray[0] = 1.record, $valarray[1] = 2.record, ... )
Returns
bool "TRUE" or "FALSE" if Table already exists, could not create Table, could not create Records

Definition at line 144 of file db_common.inc.php.

145{
146 global $g_lasttable;
147
148 if ($tablename == null || $tablename == "")
149 $tablename = $g_lasttable;
150 $g_lasttable = $tablename;
151
152 if (db_table_exists($tablename))
153 return false;
154
155 if (is_string($fieldnames))
156 $fieldnames = preg_split("/[\r\n,]/", $fieldnames);
157 if (is_string($fieldattrib))
158 $fieldattrib = preg_split("/[\r\n,]/", $fieldattrib);
159 $attribs = count($fieldattrib);
160 if (count($fieldnames) != $attribs) {
161 trigger_error(__FUNCTION__ . ": both arrays must be same length.");
162 return false;
163 }
164 $sql = "CREATE TABLE " . APPPREFIX . "$tablename (";
165 $sql .= "$idfield int(11) NOT NULL PRIMARY KEY ";
166 if ($attribs != 0) {
167 $sql .= ", ";
168
169 for($i = 0; $i < $attribs; $i++)
170 $sql .= $fieldnames[$i] . " " . $fieldattrib[$i] . ($i < $attribs - 1 ? ", " : "");
171 }
172 $sql .= ")";
173 // Send the sql command
174 $result = raw_db_query($sql);
175 if (!$result) {
176 trigger_error(__FUNCTION__ . ": could not create table $tablename.");
177 return false;
178 }
179
180 if ($valarray)
181 foreach($valarray as $values) {
182 $result = db_create_record($tablename, $fieldnames, $values, $idfield);
183 if ($result === false) {
184 return false;
185 }
186 }
187 return $result;
188}
db_table_exists($tablename)
db_create_record($tablename, $fieldnames=null, $fieldvalues=null, $idfield="id")

References $result, db_create_record(), db_table_exists(), and raw_db_query().

◆ db_delete_field()

db_delete_field ( $tablename,
$field )

db_delete_field()

Parameters
$tablename
$field
Returns
bool "TRUE" or "FALSE"

Definition at line 260 of file db_common.inc.php.

261{
262 return raw_db_delete_field(APPPREFIX . $tablename, $field);
263}
raw_db_delete_field($tablename, $field)

References raw_db_delete_field().

◆ db_delete_records()

db_delete_records ( $tablename,
$idarray,
$idfield = "id" )

db_delete_records()

Delete record from table $tablename.

Parameters
$tablename
$idarraythe id or id array
Returns
bool "TRUE" or "FALSE"

Definition at line 363 of file db_common.inc.php.

364{
365 global $g_lasttable;
366
367 if ($idarray == null || $idarray <= 0)
368 return false;
369 if (!is_array($idarray))
370 $idarray = array($idarray);
371
372 if (!$tablename)
373 $tablename = $g_lasttable;
374 $g_lasttable = $tablename;
375
376 foreach($idarray as $item) {
377 // Send the SQL command
378 $sql = "DELETE FROM " . APPPREFIX . $tablename . " WHERE $idfield = " . $item;
379 $result = raw_db_query($sql);
380 if (!$result) {
381 trigger_error(__FUNCTION__ . ": could not delete record $id in table $tablename.");
382 return false;
383 }
384 }
385 return true;
386}

References $result, and raw_db_query().

◆ db_delete_table()

db_delete_table ( $tablename)

db_delete_table()

Parameters
$tablename
Returns
bool "TRUE" or "FALSE"

Definition at line 196 of file db_common.inc.php.

197{
198 global $g_lasttable;
199
200 if (!$tablename)
201 $tablename = $g_lasttable;
202 $g_lasttable = $tablename;
203
204 if ($tablename == null || $tablename == "")
205 return false;
206 if (db_table_exists($tablename))
207 $result = raw_db_query("DROP table " . APPPREFIX . $tablename);
208 return $result;
209}

References $result, db_table_exists(), and raw_db_query().

◆ db_edit_field()

db_edit_field ( $tablename,
$field,
$type )

db_edit_field() edit field attribute

Parameters
$tablename
$field
$type
Returns
bool "TRUE" or "FALSE"

Definition at line 288 of file db_common.inc.php.

289{
290 return raw_db_edit_field(APPPREFIX . $tablename, $field, $type);
291}
raw_db_edit_field($tablename, $field, $type)

References raw_db_edit_field().

◆ db_edit_record()

db_edit_record ( $tablename,
$id = 0,
$fieldnames = null,
$fieldvalues = null,
$idfield = "id" )

db_edit_record()

Edits a record from table $tablename. If $id is null, zero or < 0, inserts a new record.

Parameters
$tablenameIf NULL uses the table used in last function call.
integer$id
unknown$fieldnamesArray or CSV string with field names, one per line. If NULL, affects all fields.
unknown$fieldvaluesArray or CSV string with field values, one per line.
string$idfield
Returns
id of the affected record or FALSE on error

Definition at line 400 of file db_common.inc.php.

401{
402 global $g_lasttable;
403
404 if ($id == null || $id <= 0) { // Create a new record
405 return db_create_record($tablename, $fieldnames, $fieldvalues, $idfield);
406 } else { // Edit existing record
407 if (!$tablename)
408 $tablename = $g_lasttable;
409 $g_lasttable = $tablename;
410 // Build the two arrays
411 if (!$fieldnames) {
412 $fieldnames = db_list_table_fields($tablename);
413 array_shift($fieldnames);
414 }
415 if (!$fieldvalues) {
416 $fieldvalues = array_fill(0, count($fieldnames), 0);
417
418 }
419
420 $names = is_string($fieldnames) ? preg_split("/[\r\n]/", $fieldnames) : $fieldnames;
421 $values = is_string($fieldvalues) ? preg_split("/[\r\n]/", $fieldvalues) : $fieldvalues;
422
423 if (count($names) != count($values)) {
424 trigger_error(__FUNCTION__ . ": both arrays must be same length.\n");
425 return false;
426 }
427 // Build the SQL query
428 $nfields = count($names);
429 for($i = 0, $str = ""; $i < $nfields; $i++) {
430 $str .= $names[$i] . "='" . db_escape_string($values[$i]) . "'" .
431 ($i < $nfields - 1 ? ", " : "");
432 }
433
434 $sql = "UPDATE " . APPPREFIX . "$tablename SET $str WHERE $idfield=$id";
435 // Send the SQL command
436 $result = raw_db_query($sql);
437 if (!$result) {
438 trigger_error(__FUNCTION__ . ": could not edit record $id in table $tablename.");
439 return false;
440 }
441 return $id;
442 }
443}

References $result, db_create_record(), db_escape_string(), db_list_table_fields(), and raw_db_query().

Referenced by db_swap_records().

+ Here is the caller graph for this function:

◆ db_escape_string()

db_escape_string ( $str)

db_escape_string()

Parameters
$str
Returns
string escaped

string mysql_real_escape_string ( string unescaped_string [, resource link_identifier])

Definition at line 732 of file db_common.inc.php.

733{
734 /**
735 * string mysql_real_escape_string ( string unescaped_string [, resource link_identifier])
736 */
737
738 return raw_db_escape_string($str);
739}
raw_db_escape_string($str)

References raw_db_escape_string().

Referenced by db_create_record(), and db_edit_record().

+ Here is the caller graph for this function:

◆ db_fetch_array()

db_fetch_array ( $result,
$type = FETCH_NUM )

db_fetch_array()

Parameters
$result
$type
Returns
array

array mysql_fetch_array ( resource result [, int result_type]) int type MYSQL_ASSOC, MYSQL_NUM ( == fetch_row), and MYSQL_BOTH

Definition at line 705 of file db_common.inc.php.

706{
707 /**
708 * array mysql_fetch_array ( resource result [, int result_type])
709 * int type MYSQL_ASSOC, MYSQL_NUM ( == fetch_row), and MYSQL_BOTH
710 */
711
712 return raw_db_fetch_array($result, $type);
713}
raw_db_fetch_array($result, $type=FETCH_BOTH)

References $result, and raw_db_fetch_array().

Referenced by db_create_record(), db_get_data(), db_get_id(), db_get_next_free_id(), db_swap_records(), and raw_db_list_table_fields_def().

+ Here is the caller graph for this function:

◆ db_free_result()

db_free_result ( $result)

db_free_result()

Parameters
$result
Returns
bool "TRUE" or "FALSE"

Definition at line 721 of file db_common.inc.php.

722{
724}
raw_db_free_result($result)

References $result, and raw_db_free_result().

Referenced by db_get_data(), and db_get_id().

+ Here is the caller graph for this function:

◆ db_get_data()

db_get_data ( $tablename,
$id = null,
$col = null,
$where = "",
$result_type = FETCH_NUM,
$idfield = "id",
$orderby = "" )

db_get_data()

Reads data from table $tablename.

$tablename Table name. If NULL uses the table used in last function call. $id Identifier(s). May be an array or a CSV string $col Column(s) or field(s). May be an array or a CSV string $where Additional WHERE clause $result_type May be FETCH_ASSOC, FETCH_BOTH or FETCH_NUM $idfield Name of id field $orderby Additional ORDER BY clause

$id $col returns

int null array with the whole record $id int str the value of column $col from record $id int str[] array with column values in array $col of record $id int[] null array of arrays with values from all columns of the $id registers int[] str array with the values of column $col from the $id registers int[] str[] 2-D array with the values of columns $col from the $id registers null null array of arrays with the whole table null str array with values of the $col column from the whole table null str[] array of arrays with the values of the columns $col from all table

Parameters
$tablename
unknown$id
unknown$col
string$where
unknown$result_type
string$idfield
string$orderby
Returns
result or FALSE

Definition at line 535 of file db_common.inc.php.

536{
537 global $g_lasttable;
538
539 if (!$tablename)
540 $tablename = $g_lasttable;
541 $g_lasttable = $tablename;
542
543 if (is_array($col))
544 $col = implode(",", $col);
545 if ($col === null || $col === "")
546 $col = "*";
547 // Build the WHERE clause
548 if ($id !== null) {
549 if (is_string($id) && strstr($id, ",")) {
550 $id = explode(",", $id);
551 }
552 if (is_array($id)) {
553 $idcond = "";
554 for($i = 0; $i < count($id); $i++)
555 $idcond .= "$idfield = '{$id[$i]}'" . ($i < count($id) - 1 ? " OR " : "");
556 } else
557 $idcond = "$idfield = '$id'";
558
559 $condition = $where ? " WHERE ($where) AND ($idcond)" : " WHERE ($idcond)";
560 } else
561 $condition = $where ? " WHERE ($where)" : "";
562
563 $orderby = $orderby ? " ORDER BY $orderby" : "";
564 // Do the query
565 $sql = "SELECT $col FROM " . APPPREFIX . $tablename . $condition . $orderby;
566
567 $result = raw_db_query($sql);
568 if (!$result)
569 return false;
570 // Loop to build the return array
571 $array = array();
572 while ($row = db_fetch_array($result, $result_type)) {
573 if (count($row) == 1)
574 $row = array_shift($row);
575 $array[] = $row;
576 }
577 if (db_free_result($result) === false) return false;
578 // Return the result
579 if (!is_array($array))
580 return $array;
581
582 switch (count($array)) {
583 case 0:
584 return false;
585
586 case 1:
587
588 $test = $array; // Copy array
589 $elem = array_shift($test); // 1st element of array...
590 if (is_null($elem)) // ...is it null?
591 return false; // Yes: return null
592 if (is_scalar($elem)) // ...is it a scalar?
593 return $elem; // Yes: return the element alone
594 else
595 return $array; // No: return the whole array
596 default:
597 return $array;
598 }
599}
db_free_result($result)

References $result, db_fetch_array(), db_free_result(), and raw_db_query().

Referenced by db_get_index().

+ Here is the caller graph for this function:

◆ db_get_id()

db_get_id ( $tablename,
$index,
$idfield = "id" )

db_get_id()

Returns the id of the record indexed by $index

Parameters
$tablename
$index
string$idfield
Returns
id or FALSE

Definition at line 629 of file db_common.inc.php.

630{
631 global $g_lasttable;
632
633 if (!is_scalar($index)) {
634 trigger_error(__FUNCTION__ . ": index must be an integer");
635 return false;
636 } else
637 $index = (int)$index;
638
639 if (!$tablename)
640 $tablename = $g_lasttable;
641 $g_lasttable = $tablename;
642
643 // Do the query
644 $sql = "SELECT $idfield FROM " . APPPREFIX . $tablename . " LIMIT 1 OFFSET $index";
645
646 $result = raw_db_query($sql);
647 if (!$result)
648 return false;
649
651
652 if (db_free_result($result) === false)
653 return false;
654
655 return $ret[0];
656}

References $result, db_fetch_array(), db_free_result(), FETCH_NUM, and raw_db_query().

◆ db_get_index()

db_get_index ( $tablename,
$id,
$idfield = "id" )

db_get_index()

Returns the index of the record identified by $id

Parameters
$tablename
$id
string$idfield
Returns
index or FALSE

Definition at line 612 of file db_common.inc.php.

613{
614 $data = db_get_data($tablename, null, $idfield);
615 return array_search($id, $data);
616}
db_get_data($tablename, $id=null, $col=null, $where="", $result_type=FETCH_NUM, $idfield="id", $orderby="")

References db_get_data().

◆ db_get_info()

db_get_info ( $info = "")

db_get_info() Returns database and wrapper version information

Parameters
string$what
Returns
string

Definition at line 35 of file db_common.inc.php.

36{
37 switch (strtolower($info)) {
38 case "version":
39 return DB_DATABASE . " " . raw_get_db_version() . " with Database Wrapper " . DB_WRAPVERSION;
40
41 case "dbtype":
42 return DB_DATABASE;
43
44 case "dbversion":
45 return raw_get_db_version();
46
47 case "wrapversion":
48 return DB_WRAPVERSION;
49 }
50}
const DB_WRAPVERSION
raw_get_db_version()

References DB_WRAPVERSION, and raw_get_db_version().

◆ db_get_next_free_id()

db_get_next_free_id ( $tablename,
$idfield = "id" )

db_get_next_free_id()

Returns the next available id in table $tablename.

Parameters
$tablename
string$idfield
Returns
id or FALSE

Definition at line 667 of file db_common.inc.php.

668{
669 global $g_current_db;
670 global $g_lasttable;
671
672 if (!$tablename)
673 $tablename = $g_lasttable;
674 $g_lasttable = $tablename;
675
676 $sql = "SELECT max($idfield) FROM " . APPPREFIX . $tablename;
677 $result = raw_db_query($sql);
678 if (!$result) {
679 return false;
680 }
681 $maxid = (db_fetch_array($result, FETCH_NUM)) ;
682
683 return $maxid[0] + 1;
684}

References $result, db_fetch_array(), FETCH_NUM, and raw_db_query().

Referenced by db_swap_records().

+ Here is the caller graph for this function:

◆ db_list_database_tables()

db_list_database_tables ( )

db_list_database_tables() Returns an array with the list of tables of the current database

Returns
result or "FALSE"

Definition at line 88 of file db_common.inc.php.

89{
91 if (!$tables) {
92 return false;
93 }
94 $tmp_tabs = "";
95 $prefixlen = strlen(trim(APPPREFIX));
96 if ($prefixlen > 0) {
97 foreach($tables as $table) {
98 if (!(stristr(substr($table, 0, $prefixlen), APPPREFIX) === false)) {
99 $tmp_tabs[] = substr($table, strlen(APPPREFIX));
100 }
101 }
102 if ($tmp_tabs == "") {
103 return false;
104 }
105 return $tmp_tabs;
106 } else return $tables;
107}
raw_db_list_database_tables()

References raw_db_list_database_tables().

◆ db_list_table_fields()

db_list_table_fields ( $tablename,
$type = false )

db_list_table_fields()

Parameters
$tablename
Returns
array with the names of the fields of table $tablename or FALSE

Definition at line 228 of file db_common.inc.php.

229{
230 global $g_lasttable;
231
232 if (!$tablename)
233 $tablename = $g_lasttable;
234 $g_lasttable = $tablename;
235
236 $result = raw_db_list_table_fields_def(APPPREFIX . $tablename, $type);
237 return $result;
238}
raw_db_list_table_fields_def($tablename, $type=false)

References $result, and raw_db_list_table_fields_def().

Referenced by db_create_record(), and db_edit_record().

+ Here is the caller graph for this function:

◆ db_open_database()

db_open_database ( $database,
$server = "",
$username = "",
$password = "" )

db_open_database() Opens and connects an existing database.

Parameters
$database
string$server
string$username
string$password
Returns
resource or "FALSE"

Definition at line 62 of file db_common.inc.php.

63{
64 return raw_db_open_database($database, $server, $username , $password);
65}
if(DB_WRAPVERSION !=DB_MYSQL_WRAP) raw_db_open_database($database, $server="", $username="", $password="")

References raw_db_open_database().

◆ db_query()

db_query ( $query)

depricated exists only for compatibility to previous version is the same as raw_db_query does not handle APPPREFIX

Definition at line 693 of file db_common.inc.php.

694{
695 return raw_db_query($query);
696}

References raw_db_query().

Referenced by raw_db_list_table_fields_def().

+ Here is the caller graph for this function:

◆ db_rename_field()

db_rename_field ( $tablename,
$field,
$newname,
$type )

db_rename_field()

Parameters
$tablename
$field
$newname
$type
Returns
bool "TRUE" or "FALSE"

Definition at line 274 of file db_common.inc.php.

275{
276 return raw_db_rename_field(APPPREFIX . $tablename, $field, $newname, $type);
277}
raw_db_rename_field($tablename, $field, $newname, $type)

References raw_db_rename_field().

◆ db_rename_table()

db_rename_table ( $tablename,
$newname )

db_rename_table()

Parameters
$tablename
$newname
Returns
bool "TRUE" or "FALSE"

Definition at line 218 of file db_common.inc.php.

219{
220 return raw_db_rename_table(APPPREFIX . $tablename, APPPREFIX . $newname);
221}
raw_db_rename_table($tablename, $newname)

References raw_db_rename_table().

◆ db_swap_records()

db_swap_records ( $tablename,
$id1,
$id2,
$idfield = "id",
$xchangeid = true )

db_swap_records()

Swaps values from two records, including the id field or not according to $xchangeid.

Parameters
$tablename
$id1
$id2
string$idfield
boolean$xchangeid
Returns
bool

Definition at line 457 of file db_common.inc.php.

458{
459 global $g_lasttable;
460 // Table name
461 if (!$tablename)
462 $tablename = $g_lasttable;
463 $g_lasttable = $tablename;
464 $table = APPPREFIX . "$tablename";
465 // Build SQL strings
466 $result = raw_db_query("SELECT * FROM $table WHERE $idfield = $id1");
467 if (!$result) {
468 trigger_error(__FUNCTION__ . ": could not read record $id1 in table $tablename.");
469 return false;
470 }
472 $fieldvalues1 = array_values($a);
473 $fieldnames1 = array_keys($a);
474 array_shift($fieldvalues1);
475 array_shift($fieldnames1);
476
477 $result = raw_db_query("SELECT * FROM $table WHERE $idfield = $id2");
478 if (!$result) {
479 trigger_error(__FUNCTION__ . ": could not read record $id2 in table $tablename.");
480 return false;
481 }
483 $fieldvalues2 = array_values($a);
484 $fieldnames2 = array_keys($a);
485 array_shift($fieldvalues2);
486 array_shift($fieldnames2);
487 // Exchange values
488 if (db_edit_record($tablename, $id1, $fieldnames2, $fieldvalues2, $idfield) === false) return false;
489 if (db_edit_record($tablename, $id2, $fieldnames1, $fieldvalues1, $idfield) === false) return false;
490 // Exchange id's
491 if ($xchangeid) {
492 $unique = db_get_next_free_id($tablename);
493 if (db_edit_record($tablename, $id1, array($idfield), array($unique), $idfield) === false) return false;
494 if (db_edit_record($tablename, $id2, array($idfield), array($id1), $idfield) === false) return false;
495 if (db_edit_record($tablename, $unique, array($idfield), array($id2), $idfield) === false) return false;
496 }
497 return true;
498}
db_get_next_free_id($tablename, $idfield="id")
db_edit_record($tablename, $id=0, $fieldnames=null, $fieldvalues=null, $idfield="id")
const FETCH_ASSOC

References $result, db_edit_record(), db_fetch_array(), db_get_next_free_id(), FETCH_ASSOC, and raw_db_query().

◆ db_table_exists()

db_table_exists ( $tablename)

db_table_exists()

Parameters
$tablenameof an opened database
Returns
bool "TRUE" if table $tablename exists in the current database

Definition at line 124 of file db_common.inc.php.

125{
126 global $g_lasttable;
127
128 if (!$tablename)
129 $tablename = $g_lasttable;
130 $g_lasttable = $tablename;
131 return raw_db_table_exists(APPPREFIX . $tablename);
132}
raw_db_table_exists($tablename)

References raw_db_table_exists().

Referenced by db_create_table(), and db_delete_table().

+ Here is the caller graph for this function:

Variable Documentation

◆ $_mainpath

$_mainpath = pathinfo(__FILE__)

Definition at line 23 of file db_common.inc.php.

◆ DB_WRAPVERSION

const DB_WRAPVERSION "db_v2b"

WINBINDER - The native Windows binding for PHP for PHP

Copyright � Hypervisual - see LICENSE.TXT for details Authors: Rubem Pechansky and Hans Rebel

Database wrapper functions for WinBinder version 2b tested with SQLite and mySQL 7.mar

Definition at line 18 of file db_common.inc.php.

Referenced by db_get_info().

◆ if

if(!defined("DB_DATABASE")) define("DB_DATABASE" ( ! defined"APPPREFIX")

Definition at line 20 of file db_common.inc.php.