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 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
| <?php
/*
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
*/
class mysql
{
var $linkid; // MySQL Resource ID
var $host; // MySQL Host name
var $user; // MySQL Username
var $pswd; // MySQL password
var $db; // MySQL Database
var $query; // MySQL query
var $query_time; // Time it took to run the query
var $pass_query; // Query passed by argument
var $result; // Query result
var $line; // Line of query
var $file; // File of query
var $error; // Any error message encountered while running
var $log_path; // The path to the log file
var $querycount; // Total number of queries executed since class inception
var $error_debug; // Allows for error debug output
var $query_debug; // Allows for output of all queries all the time
var $super_debug; // Allows output of ALL debugging output
/* Class constructor. Initializes the host, user, pswd, db and log fields */
function mysql($host, $user, $pswd, $db, $log_path = './')
{
/*#
#
# The following was moved to the config file for
# ease of use by the admin (so they don't have to config
# multiple files, and only have to edit one),
# but the original source was left here for those who wish
# to implement this class in their own creations.
#
# to enable, just change /*# above to //*# and edit settings
#
# to disable, change //*# above to /*#
# and copy-paste this section into your own config file
#
// BEGIN CONFIG ----------------------
define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
define ('DB_ERR_LOG_ERRORS' , true); // (true / false) set to true to log errors in mysql.err file
define ('DB_ERR_TO' , 'yourname@yoursite.com'); // set your TO email address
define ('DB_ERR_SUBJECT' , 'Query Error'); // don't really need to change this
define ('DB_ERR_FROM' , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above)
define ('FILE_PATH_END' , '/yourscript/'); // the name of the directory containing the script (with wrapping / )
// END CONFIG ------------------------
#
# end of config section removal
#
#*/
$this->host = $host;
$this->user = $user;
$this->pswd = $pswd;
$this->db = $db;
$this->log_path = $log_path;
// each of these can be set independently as needed
$this->error_debug = false; // set to true for output of errors
$this->query_debug = false; // set to true for output of every query
$this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.)
// make sure the log path ends with /
if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1))
{
$this->log_path .= '/';
}
}
/* Connect to the MySQL database server */
/*function connect( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->load_arguments($args);
}
//$this->linkid = mysql_connect($this->host, $this->user, $this->pswd);
$this->linkid = mysqli_query ($this->host, $this->user, $this->pswd);
if ( ! $this->linkid)
{
$this->error = mysql_errno( ).': '.mysql_error( );
$this->error_report( );
if ($this->error_debug)
{
echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
}
else
{
die('There was a database error. An email has been sent to the system administrator.');
}
}
}
*/
function connect( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->load_arguments($args);
}
$this->linkid = @mysqli_connect($this->host, $this->user, $this->pswd);
if (mysqli_connect_error())
{
$this->error = mysqli_connect_errno( ).': '.mysqli_connect_error( );
$this->error_report( );
if ($this->error_debug)
{
echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
}
else
{
die('There was a database error. An email has been sent to the system administrator.');
}
}
}
/* Selects the MySQL Database */
/*function select( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->load_arguments($args);
}
if ( ! @mysql_select_db($this->db, $this->linkid))
{
$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
$this->error_report( );
if ($this->error_debug)
{
echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
}
else
{
die('There was a database error. An email has been sent to the system administrator.');
}
}
}
*/
function select( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->load_arguments($args);
}
if ( ! @mysqli_select_db($this->linkid, $this->db ))
{
$this->error = mysqli_errno($this->linkid).': '.mysqli_error($this->linkid);
$this->error_report( );
if ($this->error_debug)
{
echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
}
else
{
die('There was a database error. An email has been sent to the system administrator.');
}
}
}
/* Connects to the server AND selects the default database in one function */
function connect_select( )
{
$num_args = func_num_args( );
$args = func_get_args( );
$this->clear_arguments( );
// get the arguments, if any
if (0 != $num_args)
{
$this->load_arguments($args);
}
$this->connect( );
$this->select( );
}
/* Execute Database Query */
function query( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( ); // don't clear unless we have new
$this->load_arguments($args);
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
}
}
if ($this->super_debug)
{
echo 'QUERY ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
$done = true; // innocent until proven guilty
// start time logging
$time = microtime_float( );
$this->result = @mysql_query($this->query, $this->linkid);
$this->query_time = microtime_float( ) - $time;
if ($this->query_debug)
{
$this->query = trim(preg_replace('/\\s+/', ' ', $this->query));
echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>";
}
if ( ! $this->result)
{
$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
$this->error_report( );
if ($this->error_debug)
{
echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>";
print_r(debug_backtrace( ));
}
else
{
$this->error = 'There was a database error. An email has been sent to the system administrator.';
}
$done = false;
}
if ($done)
{
$this->querycount++;
return $this->result;
}
return false;
}
/* Determine total rows affected by query */
function affected_rows( )
{
$count = @mysql_affected_rows($this->linkid);
return $count;
}
/* Determine total rows returned by query */
function num_rows( )
{
$count = @mysql_num_rows($this->result);
if ( ! $count)
{
return 0;
}
return $count;
}
/** public function insert
* Insert the associative data array into the table.
* $data['field_name'] = value
* $data['field_name2'] = value2
* If the field name has a trailing space: $data['field_name ']
* then the query will insert the data with no sanitation
* or wrapping quotes (good for function calls, like NOW( )).
*
* @param string table name
* @param array associative data array
* @param string [optional] where clause (for updates)
* @param bool [optional] whether or not we should replace values (true / false)
* @action execute a mysql query
* @return int insert id for row
*/
function insert($table, $data_array, $where = '', $replace = false)
{
$where = trim($where);
$replace = (bool) $replace;
if ('' == $where) {
$query = (false == $replace) ? ' INSERT ' : ' REPLACE ';
$query .= ' INTO ';
}
else {
$query = ' UPDATE ';
}
$query .= '`'.$table.'`';
if ( ! is_array($data_array)) {
throw new MySQLException(__METHOD__.': Trying to insert non-array data');
}
else {
$query .= ' SET ';
foreach ($data_array as $field => $value) {
if (is_null($value)) {
$query .= " `{$field}` = NULL , ";
}
elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL
$field = trim($field);
$query .= " `{$field}` = {$value} , ";
}
else {
$query .= " `{$field}` = '".sani($value)."' , ";
}
}
$query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces)
}
$query .= ' '.$where.' ';
$this->query = $query;
$return = $this->query( );
if ('' == $where) {
return $this->fetch_insert_id( );
}
else {
return $return;
}
}
/** public function multi_insert
* Insert the array of associative data arrays into the table.
* $data[0]['field_name'] = value
* $data[0]['field_name2'] = value2
* $data[0]['DBWHERE'] = where clause [optional]
* $data[1]['field_name'] = value
* $data[1]['field_name2'] = value2
* $data[1]['DBWHERE'] = where clause [optional]
*
* @param string table name
* @param array associative data array
* @param bool [optional] whether or not we should replace values (true / false)
* @action execute multiple mysql queries
* @return array insert ids for rows (with original keys preserved)
*/
function multi_insert($table, $data_array, $replace = false)
{
if ( ! is_array($data_array)) {
throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data');
}
else {
$result = array( );
foreach ($data_array as $key => $row) {
$where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : '';
unset($row['DBWHERE']);
$result[$key] = $this->insert($table, $row, $where, $replace);
}
}
return $result;
}
/** public function delete
* Delete the row from the table
*
* @param string table name
* @param string where clause
* @action execute a mysql query
* @return result
*/
function delete($table, $where)
{
$query = "
DELETE
FROM `{$table}`
{$where}
";
$this->query = $query;
try {
return $this->query( );
}
catch (MySQLException $e) {
throw $e;
}
}
/** public function multi_delete
* Delete the array of data from the table.
* $table[0] = table name
* $table[1] = table name
*
* $where[0] = where clause
* $where[1] = where clause
*
* If recursive is true, all combinations of table name
* and where clauses will be executed.
*
* If only one table name is set, that table will
* be used for all of the queries, looping through
* the where array
*
* If only one where clause is set, that where clause
* will be used for all of the queries, looping through
* the table array
*
* @param mixed table name array or single string
* @param mixed where clause array or single string
* @param bool optional recursive (default false)
* @action execute multiple mysql queries
* @return array results
*/
function multi_delete($table_array, $where_array, $recursive = false)
{
if ( ! is_array($table_array)) {
$recursive = false;
$table_array = (array) $table_array;
}
if ( ! is_array($where_array)) {
$recursive = false;
$where_array = (array) $where_array;
}
if ($recursive) {
foreach ($table_array as $table) {
foreach ($where_array as $where) {
$result[] = $this->delete($table, $where);
}
}
}
else {
if (count($table_array) == count($where_array)) {
for ($i = 0, $count = count($table_array); $i < $count; ++$i) {
$result[] = $this->delete($table_array[$i], $where_array[$i]);
}
}
elseif (1 == count($table_array)) {
$table = $table_array[0];
foreach ($where_array as $where) {
$result[] = $this->delete($table, $where);
}
}
elseif (1 == count($where_array)) {
$where = $where_array[0];
foreach ($table_array as $table) {
$result[] = $this->delete($table, $where);
}
}
else {
throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes');
}
}
return $result;
}
/* Return query result row as an object */
function fetch_object( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_OBJECT ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$row = @mysql_fetch_object($this->result);
return $row;
}
/* Return query result row as an indexed array */
function fetch_row( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_ROW ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$row = @mysql_fetch_row($this->result);
return $row;
}
/* Return query result row as an associative array */
function fetch_assoc( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_ASSOC ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$row = @mysql_fetch_assoc($this->result);
return $row;
}
/* Return query result row as an associative array and an indexed array */
function fetch_both( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_BOTH ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$row = @mysql_fetch_array($this->result, MYSQL_BOTH);
return $row;
}
/* Return query result as an array of arrays */
function fetch_array( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_ARRAY ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$arr = array( );
while ($row = @mysql_fetch_array($this->result))
{
$arr[] = $row;
}
return $arr;
}
/* Return query result as an array of single values */
function fetch_value_array( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_VALUE_ARRAY ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$arr = array( );
while ($row = @mysql_fetch_row($this->result))
{
$arr[] = $row[0];
}
return $arr;
}
/* Return single query result value */
function fetch_value( )
{
$num_args = func_num_args( );
$args = func_get_args( );
// get the arguments, if any
if (0 != $num_args)
{
$this->clear_arguments( );
$this->load_arguments($args);
}
if ($this->super_debug)
{
echo 'FETCH_VALUE ';
echo '<pre>';
print_r($this->get_arguments( ));
echo '</pre>';
}
if (false !== $this->pass_query)
{
$this->query = $this->pass_query;
$this->query( );
}
$row = @mysql_fetch_row($this->result);
return $row[0];
}
/* Return the total number of queries executed during
the lifetime of this object */
function num_queries( )
{
return $this->querycount;
}
/* get the id for the previous INSERT command */
function fetch_insert_id( )
{
return @mysql_insert_id($this->linkid);
}
/* get the errors, if any */
function fetch_error( )
{
return $this->error;
}
/* report the errors to the admin */
function error_report( )
{
// generate an error report and then act according to configuration
$error_report = "An error has been generated by the server.\nFollowing is the debug information:\n\n";
$error_report .= " * File: {$this->file_name}\n";
$error_report .= " * Line: {$this->line}\n";
$error_report .= " * Error: {$this->error}\n";
$error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}";
// if a database query caused the error, show the query
if ('' != $this->query)
{
$error_report .= " * Query: {$this->query}\n";
$error_report_short .= " [sql={$this->query}]";
}
// send the error as email if set
if (DB_ERR_EMAIL_ERRORS)
{
mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n");
}
// log the error (remove line breaks and multiple concurrent spaces)
$this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n");
}
/* log any errors */
function logger($report)
{
if (DB_ERR_LOG_ERRORS)
{
$log = $this->log_path . "mysql.err";
$fp = fopen($log,'a+');
fwrite($fp,$report);
@chmod($log, 0777);
fclose($fp);
}
}
/* extract the arguments */
function load_arguments($args)
{
foreach ($args as $arg)
{
if ($this->super_debug)
{
echo '<hr />arg = (';
echo stripslashes(var_export($arg, true)).') - ';
echo 'is_line('.var_export(is_int($arg), true).') ';
echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') ';
echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') ';
echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- ';
}
if (is_int($arg)) // it's an integer
{
if ($this->super_debug) echo 'LINE - ';
$this->line = $arg;
if ($this->super_debug) echo $this->line;
}
elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter
{
if ($this->super_debug) echo 'FILE - ';
$this->file_name = substr($arg, strpos($arg, FILE_PATH_END));
if ($this->super_debug) echo $this->file_name;
}
elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces
{
if ($this->super_debug) echo 'DATABASE - ';
$this->db = $arg;
if ($this->super_debug) echo $this->db;
}
elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word
{
if ($this->super_debug) echo 'QUERY - ';
$this->pass_query = $arg;
if ($this->super_debug) echo $this->pass_query;
}
else
{
if ($this->super_debug) echo 'UNKNOWN - ';
$arg_dump = var_export($arg, true);
$this->error = 'Unknown argument found: ' . $arg_dump;
if ($this->super_debug) echo $this->error;
}
}
// wait until after all arguments are entered before outputting error
// because the error may happen on the first argument and the other
// arguments have important error report data (it's what they're for)
if ('Unknown argument' == substr((string) $this->error, 0, 16))
{
$this->error_report( );
}
if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';}
}
/* clear the arguments */
function clear_arguments( )
{
// don't clear query or db as we may use them later
$this->line = false;
$this->file_name = false;
$this->error = false;
$this->pass_query = false;
}
/* return the arguments */
function get_arguments( )
{
$args['line'] = $this->line;
$args['file'] = $this->file_name;
$args['error'] = $this->error;
$args['query'] = $this->pass_query;
return $args;
}
} // end of mysql class
/*
+---------------------------------------------------------------------------
| > Extra SQL Functions
+---------------------------------------------------------------------------
*/
/* escape the data before it gets queried into the database */
function sani($data)
{
if (is_array($data))
{
return array_map('sani', $data);
}
else
{
if (get_magic_quotes_gpc( ))
{
$data = stripslashes($data);
}
# $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html;
if (function_exists('mysql_real_escape_string'))
{
$data = mysql_real_escape_string($data); // php 4.3.0+
}
else
{
$data = mysql_escape_string($data); // php 4.0+
}
return $data;
}
}
if ( ! function_exists('microtime_float'))
{
function microtime_float( )
{
list($usec, $sec) = explode(' ', microtime( ));
return ((float)$usec + (float)$sec);
}
}
function safe_var_export($var)
{
if ( ! is_array($var))
{
return var_export($var, true);
}
foreach ($var as $key => $data)
{
if (('GLOBALS' == $key) || ($data == $var))
{
$var[$key] = 'RECURSION';
continue;
}
}
return var_export($var, true);
} |
Partager