Changeset 423 for branches/1.1dev
- Timestamp:
- Aug 13, 2013 11:52:52 PM (11 years ago)
- Location:
- branches/1.1dev
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/config/boot.inc.php
r352 r423 76 76 77 77 // Connect to MySQL 78 $dbh = mysql_connect('localhost', $CFG->username, $CFG->password);79 80 // Select database81 mysql_select_db($CFG->database, $dbh);78 if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) { 79 // Select database 80 mysql_select_db($CFG->database, $dbh); 81 } 82 82 83 83 // Connection errors. … … 109 109 echo "<!-- --------------------------------------\n" . $debugqry . "\n-->"; 110 110 } 111 112 // Ensure we have an active connection. 113 // If we continue on a dead connection we might experience a "MySQL server has gone away" error. 114 // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html 115 // Unfortunately we'll have redundant code with the reconnection below. 116 if (!mysql_ping($dbh)) { 117 logMsg(sprintf('MySQL ping failed; reconnecting⊠("%s")', truncate(trim($debugqry), 150)), LOG_NOTICE, __FILE__, __LINE__); 118 mysql_close($dbh); 119 if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) { 120 mysql_select_db($CFG->database, $dbh); 121 } 122 if (!$dbh || mysql_error($dbh)) { 123 $mysql_error_msg = $dbh ? 'Codebase MySQL error: (' . mysql_errno($dbh) . ') ' . mysql_error($dbh) : 'Codebase MySQL error: Could not connect to server.'; 124 if ($CFG->db_debug) { 125 echo $mysql_error_msg . "\n"; 126 } else { 127 echo _("This page is temporarily unavailable. It should be back up in a few minutes."); 128 } 129 logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__); 130 die; 131 } 132 } 133 111 134 $qid = mysql_query($query, $dbh); 112 135 if (!$qid || mysql_error($dbh)) { -
branches/1.1dev/lib/Utilities.inc.php
r401 r423 154 154 * @since 29 Mar 2006 13:48:49 155 155 */ 156 function truncate($str, $len, $where='middle') 157 { 156 function truncate($str, $len, $where='end', $delim='âŠ') 157 { 158 if ($len <= 3 || mb_strlen($str) <= 3) { 159 return ''; 160 } 158 161 $part1 = floor(($len - 3) / 2); 159 162 $part2 = ceil(($len - 3) / 2); 160 163 switch ($where) { 161 164 case 'start' : 162 return preg_replace(array(sprintf('/^.{4,}(.{%s})$/ ', $part1 + $part2), '/\s*\.{3,}\s*/'), array('...$1', '...'), $str);165 return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str); 163 166 break; 164 167 default : 165 168 case 'middle' : 166 return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/ ', $part1, $part2), '/\s*\.{3,}\s*/'), array('$1...$2', '...'), $str);169 return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str); 167 170 break; 168 171 case 'end' : 169 return preg_replace(array(sprintf('/^(.{%s}).{4,}$/ ', $part1 + $part2), '/\s*\.{3,}\s*/'), array('$1...', '...'), $str);170 break; 172 return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str); 173 break; 171 174 } 172 175 }
Note: See TracChangeset
for help on using the changeset viewer.