]> git.mxchange.org Git - ctracker.git/blobdiff - libs/lib_connect.php
Continued:
[ctracker.git] / libs / lib_connect.php
index f3c0161f91a252e295cf13a92efd008be3df0a68..269062421a5aa80ce032ab03d46c9759e116b56c 100644 (file)
@@ -66,18 +66,22 @@ function isCrackerTrackerDatabaseLinkUp () {
 }
 
 // Database error detected
-function crackerTrackerDatabaseError ($F, $L) {
+function crackerTrackerDatabaseError (string $file, int $line) {
        // Should we debug?
        if (isCrackerTrackerDebug()) {
                // Output error
-               print 'Function    : ' . $F . '<br />';
-               print 'Line        : ' . $L . '<br />';
-               if (isset($GLOBALS['ctracker_link'])) {
-                       print 'MySQL error : ' . mysqli_error($GLOBALS['ctracker_link']) . '<br />';
+               print 'Function    : ' . $file . '<br />' . PHP_EOL;
+               print 'Line        : ' . $line . '<br />' . PHP_EOL;
+               if (isset($GLOBALS['ctracker_link']) && $GLOBALS['ctracker_link'] !== false) {
+                       print 'MySQL error : ' . mysqli_error($GLOBALS['ctracker_link']) . '<br />' . PHP_EOL;
                } else {
-                       print 'No MySQLi available.<br />';
+                       print 'No MySQLi available.<br />' . PHP_EOL;
+               }
+               if (isset($GLOBALS['ctracker_last_sql'])) {
+                       print 'Last SQL    : '. $GLOBALS['ctracker_last_sql'] . '<br />' . PHP_EOL;
+               } else {
+                       print 'No last SQL command available.<br />' . PHP_EOL;
                }
-               print 'Last SQL    : '. $GLOBALS['ctracker_last_sql'] . '<br />';
        }
 
        // Currently only die here
@@ -100,11 +104,11 @@ function crackerTrackerCloseDatabaseLink () {
 }
 
 // Inserts given array, if IP/check_get combination was not found
-function crackerTrackerInsertArray ($table, array $rowData) {
+function crackerTrackerInsertArray (string $table, array $rowData) {
        // Is it found?
        if (!isCrackerTrackerEntryFound($rowData)) {
                // Reset insert id
-               $GLOBALS['ctracker_last_insert_id'] = FALSE;
+               $GLOBALS['ctracker_last_insert_id'] = false;
 
                // Run it
                runCrackerTrackerSql(sprintf("INSERT INTO `%s` (`%s`) VALUES(%s)",
@@ -122,7 +126,7 @@ function crackerTrackerInsertArray ($table, array $rowData) {
 }
 
 // Updates a given entry by just counting it up
-function updateCrackerTrackerEntry (array $rowData, $countColumn = 'count') {
+function updateCrackerTrackerEntry (array $rowData, string $countColumn = 'count') {
        // The link should be up here
        if (!isCrackerTrackerDatabaseLinkUp()) {
                // Throw exception
@@ -159,7 +163,7 @@ function isCrackerTrackerEntryFound (array $rowData) {
 }
 
 // Escapes the string
-function crackerTrackerEscapeString ($string) {
+function crackerTrackerEscapeString (string $string) {
        // Is the link up?
        if (!isCrackerTrackerDatabaseLinkUp()) {
                // Then we cant use mysqli_real_escape_string!
@@ -177,7 +181,7 @@ function crackerTrackerEscapeString ($string) {
 }
 
 // Runs an SQL query and checks for errors
-function runCrackerTrackerSql ($sqlString, $function, $line) {
+function runCrackerTrackerSql (string $sqlString, string $function, int $line) {
        // Is the link up?
        if (!isCrackerTrackerDatabaseLinkUp()) {
                // Abort here
@@ -195,9 +199,9 @@ function runCrackerTrackerSql ($sqlString, $function, $line) {
 }
 
 // Checks wether a table was found
-function isCrackerTrackerTableCreated ($table) {
+function isCrackerTrackerTableCreated (string $table) {
        // Default is not found
-       $found = FALSE;
+       $found = false;
 
        // Run the query
        $result = runCrackerTrackerSql('SHOW TABLES', __FUNCTION__, __LINE__);
@@ -210,7 +214,7 @@ function isCrackerTrackerTableCreated ($table) {
                // Is the table there?
                if ($tab == $table) {
                        // Okay, found. So abort
-                       $found = TRUE;
+                       $found = true;
                        break;
                }
        }
@@ -223,7 +227,7 @@ function isCrackerTrackerTableCreated ($table) {
 }
 
 // Creates the given table with columns
-function crackerTrackerCreateTable ($table, array $columns, array $keys) {
+function crackerTrackerCreateTable (string $table, array $columns, array $keys) {
        // Begin the SQL
        $sqlString = 'CREATE TABLE IF NOT EXISTS `' . $table . '` (';
 
@@ -240,7 +244,7 @@ function crackerTrackerCreateTable ($table, array $columns, array $keys) {
        $sqlString .= 'PRIMARY KEY (`' . $table . '`), ';
 
        // Add keys
-       foreach ($keys as $key=>$type) {
+       foreach ($keys as $key => $type) {
                // Add this entry
                $sqlString .= '' . $type . ' (`' . $key . '`), ';
        }
@@ -253,7 +257,7 @@ function crackerTrackerCreateTable ($table, array $columns, array $keys) {
 }
 
 // Inits a table by inserting 
-function crackerTrackerInitTable ($table) {
+function crackerTrackerInitTable (string $table) {
        // Prepare SQL and run it
        runCrackerTrackerSql('INSERT INTO `' . $table . '` (`' . $table . '`) VALUES (NULL)');
 }
@@ -310,7 +314,7 @@ function crackerTrackerLoadConfig () {
 }
 
 // Getter for config
-function getCrackerTrackerConfig ($entry) {
+function getCrackerTrackerConfig (string $entry) {
        // Is the config entry there?
        if (!isset($GLOBALS['ctracker_config'][$entry])) {
                // Then better die here, else we may have an endless loop
@@ -332,7 +336,7 @@ function isCrackerTrackerIpSuspicious () {
        // Skip this silently if we have not config
        if (!isCrackerTrackerDatabaseLinkUp()) {
                // Skip this step silently, all is not suspicious
-               return FALSE;
+               return false;
        }
 
        // Check if an entry is there
@@ -345,7 +349,7 @@ function isCrackerTrackerIpSuspicious () {
        $found = ($rows > 0);
 
        // And again?
-       if ($found === TRUE) {
+       if ($found === true) {
                // Yes, one is found, then load it
                $result = runCrackerTrackerSql("SELECT SQL_SMALL_RESULT * FROM `ctracker_data` USE INDEX (`remote_proxy_last`) WHERE `remote_addr`='" . determineCrackerTrackerRealRemoteAddress() . "' OR `proxy_addr`='" . getenv('REMOTE_ADDR') . "' ORDER BY `last_attempt` DESC LIMIT 1", __FUNCTION__, __LINE__);
 
@@ -369,7 +373,7 @@ function ifCrackerTrackerIpHasTicket () {
        $found = (mysqli_num_rows($result) == 1);
 
        // And again?
-       if ($found === TRUE) {
+       if ($found === true) {
                // Cache the ticket data
                $GLOBALS['ctracker_last_ticket'] = mysqli_fetch_array($result);
        }