| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 3 |  |  | class DatabaseConnect extends mysqli | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 4 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  |  // The database connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 		$config = parse_ini_file('config/config.ini.php');  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		parent::__construct($config['host'], $config['username'], $config['password'], $config['dbname']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | $db = new DatabaseConnect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | if($db->connect_errno == 1203)  // 1203 == ER_TOO_MANY_USER_CONNECTIONS (mysqld_error.h) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	error_log('ER_TOO_MANY_USER_CONNECTIONS'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	sleep(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	header('location: '.$_SERVER['PHP_SELF']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | if ($db->connect_errno) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	error_log('Sorry, die Verbindung zu unserem  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         Server ist hops gegangen. Wegen '. $db -> connect_error); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	echo 'Sorry, die Verbindung zu unserem  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         Server ist hops gegangen. Wegen '. $db -> connect_error; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | /* Uncomment if you start first time | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | $query = "CREATE TABLE IF NOT EXISTS `accounts` ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 			 `id` int(11) unsigned NOT NULL auto_increment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			 `access_token` varchar(55) NOT NULL default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			 `refresh_token` varchar(55) NOT NULL default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			 `token_type` varchar(55) NOT NULL default 'bearer', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			 `expires_in` INT NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			 `expiration_date` INT NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			 `device_uid` varchar(255) NOT NULL default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			 `client_id` varchar(255) NOT NULL default '81e8a76e-1e02-4d17-9ba0-8a7020261b26', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			 `distinct_id` varchar(255) NOT NULL default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			 `city` varchar(100) default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			 `country` varchar(10) default 'DE', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			 `loc_accuracy` varchar(50) default '0.0', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			 `lat` varchar(255) default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			 `lng` varchar(255) default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			 `name` varchar(100) default '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			 `X-Client-Type` varchar(50) NOT NULL default 'android_4.24.2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			 `User-Agent` varchar(150) NOT NULL default 'Jodel/4.4.9 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			 `X-Api-Version` varchar(10) NOT NULL default '0.2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			 PRIMARY KEY  (`id`) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			 ) DEFAULT CHARSET=utf8"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | $query2 = "CREATE TABLE IF NOT EXISTS `votes` ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			 `id` int(11) unsigned NOT NULL auto_increment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			 `device_uid` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			 `postId` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			 `type` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			 PRIMARY KEY  (`id`) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			 ) DEFAULT CHARSET=utf8"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | $query3	 = "CREATE TABLE IF NOT EXISTS `users` ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			 `id` int(11) unsigned NOT NULL auto_increment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			 `device_uid` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			 `rights` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			 `user_token` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			 `remaining_votes` INT NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			 PRIMARY KEY  (`id`) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			 ) DEFAULT CHARSET=utf8"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | $queryCitys	 = "CREATE TABLE IF NOT EXISTS `citys` ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			 `id` int(11) unsigned NOT NULL auto_increment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			 `name` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			 `lat` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			 `lng` varchar(255) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			 `country` INT NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			 PRIMARY KEY  (`id`) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			 ) DEFAULT CHARSET=utf8"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |   if(!$db->query($query) || !$db->query($query2) || !$db->query($query3) || !$db->query($queryCitys)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |   { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     throw new Exception($db->error($mysqli)); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  |   } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | */ | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.