示例#1
0
 /**
  * {@inheritDoc}
  */
 function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
 {
     $connect_string = '';
     if ($sqluser) {
         $connect_string .= "user={$sqluser} ";
     }
     if ($sqlpassword) {
         $connect_string .= "password={$sqlpassword} ";
     }
     if ($sqlserver) {
         // $sqlserver can carry a port separated by : for compatibility reasons
         // If $sqlserver has more than one : it's probably an IPv6 address.
         // In this case we only allow passing a port via the $port variable.
         if (substr_count($sqlserver, ':') === 1) {
             list($sqlserver, $port) = explode(':', $sqlserver);
         }
         if ($sqlserver !== 'localhost') {
             $connect_string .= "host={$sqlserver} ";
         }
         if ($port) {
             $connect_string .= "port={$port} ";
         }
     }
     $schema = '';
     if ($database) {
         $this->dbname = $database;
         if (strpos($database, '.') !== false) {
             list($database, $schema) = explode('.', $database);
         }
         $connect_string .= "dbname={$database}";
     }
     $this->persistency = $persistency;
     if ($this->persistency) {
         if (!function_exists('pg_pconnect')) {
             $this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?';
             return $this->sql_error('');
         }
         $collector = new \phpbb\error_collector();
         $collector->install();
         $this->db_connect_id = !$new_link ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
     } else {
         if (!function_exists('pg_connect')) {
             $this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?';
             return $this->sql_error('');
         }
         $collector = new \phpbb\error_collector();
         $collector->install();
         $this->db_connect_id = !$new_link ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
     }
     $collector->uninstall();
     if ($this->db_connect_id) {
         if ($schema !== '') {
             @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema);
         }
         return $this->db_connect_id;
     }
     $this->connect_error = $collector->format_errors();
     return $this->sql_error('');
 }
示例#2
0
 public function test_collection_with_mask()
 {
     $collector = new \phpbb\error_collector(E_ALL & ~E_NOTICE);
     // not collecting notices
     $collector->install();
     // Cause a warning
     1 / 0;
     $line = __LINE__;
     // Cause a notice
     $array = array('ITEM' => 'value');
     $value = $array[ITEM];
     $line2 = __LINE__;
     $collector->uninstall();
     // The notice should not be collected
     $this->assertEmpty($collector->errors[1]);
     list($errno, $msg_text, $errfile, $errline) = $collector->errors[0];
     $error_contents = $collector->format_errors();
     $this->assertEquals($errno, 2);
     // Unfortunately $error_contents will contain the full path here,
     // because the tests directory is outside of phpbb root path.
     $this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents);
     $this->assertStringEndsWith(" line {$line}", $error_contents);
 }
/**
* Wrapper for sending out emails with the PHP's mail function
*/
function phpbb_mail($to, $subject, $msg, $headers, $eol, &$err_msg)
{
    global $config, $phpbb_root_path, $phpEx;
    // We use the EOL character for the OS here because the PHP mail function does not correctly transform line endings. On Windows SMTP is used (SMTP is \r\n), on UNIX a command is used...
    // Reference: http://bugs.php.net/bug.php?id=15841
    $headers = implode($eol, $headers);
    if (!class_exists('\\phpbb\\error_collector')) {
        include $phpbb_root_path . 'includes/error_collector.' . $phpEx;
    }
    $collector = new \phpbb\error_collector();
    $collector->install();
    // On some PHP Versions mail() *may* fail if there are newlines within the subject.
    // Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
    // Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space (Use '' as parameter to mail_encode() results in SPACE used)
    $result = $config['email_function_name']($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);
    $collector->uninstall();
    $err_msg = $collector->format_errors();
    return $result;
}