]> git.mxchange.org Git - friendica.git/commitdiff
Set the charset for the SQL connection for new installations
authorMichael Vogel <ike@pirati.ca>
Thu, 1 Sep 2016 03:50:41 +0000 (03:50 +0000)
committerMichael Vogel <ike@pirati.ca>
Thu, 1 Sep 2016 03:50:41 +0000 (03:50 +0000)
htconfig.php
include/dba.php
view/templates/htconfig.tpl

index fe6c0d82ee4562275a88beb8b301870b5c0b4543..469fa7af6116f0ae64cb427d6c9064b7dda71bc0 100644 (file)
@@ -16,6 +16,11 @@ $db_user = 'mysqlusername';
 $db_pass = 'mysqlpassword';
 $db_data = 'mysqldatabasename';
 
+// Set the database connection charset to UTF8.
+// Changing this value will likely corrupt the special characters.
+// You have been warned.
+$a->config['system']['db_charset'] = "utf8mb4";
+
 // Choose a legal default timezone. If you are unsure, use "America/Los_Angeles".
 // It can be changed later and only applies to timestamps for anonymous viewers.
 
index b0927265be9006e24bc16e368b86763ae690bb23..5e84b95df559a18a2878e09e4fa675bc99d85172 100644 (file)
@@ -66,6 +66,8 @@ class dba {
                        if(! mysqli_connect_errno()) {
                                $this->connected = true;
                        }
+                       if (isset($a->config["system"]["db_charset"]))
+                               $this->db->set_charset($a->config["system"]["db_charset"]);
                }
                else {
                        $this->mysqli = false;
@@ -73,6 +75,8 @@ class dba {
                        if($this->db && mysql_select_db($db,$this->db)) {
                                $this->connected = true;
                        }
+                       if (isset($a->config["system"]["db_charset"]))
+                               mysql_set_charset($a->config["system"]["db_charset"], $this->db);
                }
                if(! $this->connected) {
                        $this->db = null;
@@ -95,6 +99,14 @@ class dba {
 
                $this->error = '';
 
+               // Check the connection (This can reconnect the connection - if configured)
+               if ($this->mysqli)
+                       $connected = $this->db->ping();
+               else
+                       $connected = mysql_ping($this->db);
+
+               $connstr = ($connected ? "Connected": "Disonnected");
+
                $stamp1 = microtime(true);
 
                if($this->mysqli)
@@ -122,14 +134,17 @@ class dba {
                }
 
                if($this->mysqli) {
-                       if($this->db->errno)
+                       if($this->db->errno) {
                                $this->error = $this->db->error;
+                               $this->errorno = $this->db->errno;
+                       }
+               } elseif(mysql_errno($this->db)) {
+                       $this->error = mysql_error($this->db);
+                       $this->errorno = mysql_errno($this->db);
                }
-               elseif(mysql_errno($this->db))
-                               $this->error = mysql_error($this->db);
 
                if(strlen($this->error)) {
-                       logger('dba: ' . $this->error);
+                       logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error);
                }
 
                if($this->debug) {
index cbbd14dc4eadc1cf1357282140b83cf3ffd4ce56..df793197cea8d398829fce03eac42a9b8419dd1b 100644 (file)
@@ -15,6 +15,11 @@ $db_user = '{{$dbuser}}';
 $db_pass = '{{$dbpass}}';
 $db_data = '{{$dbdata}}';
 
+// Set the database connection charset to UTF8.
+// Changing this value will likely corrupt the special characters.
+// You have been warned.
+$a->config['system']['db_charset'] = "utf8mb4";
+
 // email adress for the system admin
 
 $a->config['admin_email'] = '{{$adminmail}}';