当前位置: 首页>>代码示例>>PHP>>正文


PHP fCore::checkOs方法代码示例

本文整理汇总了PHP中fCore::checkOs方法的典型用法代码示例。如果您正苦于以下问题:PHP fCore::checkOs方法的具体用法?PHP fCore::checkOs怎么用?PHP fCore::checkOs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fCore的用法示例。


在下文中一共展示了fCore::checkOs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: connectToDatabase

 /**
  * Connects to the database specified if no connection exists
  * 
  * @return void
  */
 private function connectToDatabase()
 {
     // Don't try to reconnect if we are already connected
     if ($this->connection) {
         return;
     }
     // Establish a connection to the database
     if ($this->extension == 'pdo') {
         $odbc = strtolower(substr($this->database, 0, 4)) == 'dsn:';
         if ($this->type == 'mssql') {
             if ($odbc) {
                 $dsn = 'odbc:' . substr($this->database, 4);
             } else {
                 $separator = fCore::checkOS('windows') ? ',' : ':';
                 $port = $this->port ? $separator . $this->port : '';
                 $driver = fCore::checkOs('windows') ? 'mssql' : 'dblib';
                 $dsn = $driver . ':host=' . $this->host . $port . ';dbname=' . $this->database;
             }
         } elseif ($this->type == 'mysql') {
             if (substr($this->host, 0, 5) == 'sock:') {
                 $dsn = 'mysql:unix_socket=' . substr($this->host, 5) . ';dbname=' . $this->database;
             } else {
                 $port = $this->port ? ';port=' . $this->port : '';
                 $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . $port;
             }
         } elseif ($this->type == 'oracle') {
             if ($odbc) {
                 $dsn = 'odbc:' . substr($this->database, 4);
             } else {
                 $port = $this->port ? ':' . $this->port : '';
                 $dsn = 'oci:dbname=' . $this->host . $port . '/' . $this->database . ';charset=AL32UTF8';
             }
         } elseif ($this->type == 'postgresql') {
             $dsn = 'pgsql:dbname=' . $this->database;
             if ($this->host && $this->host != 'sock:') {
                 $dsn .= ' host=' . $this->host;
             }
             if ($this->port) {
                 $dsn .= ' port=' . $this->port;
             }
         } elseif ($this->type == 'sqlite') {
             $dsn = 'sqlite:' . $this->database;
         }
         try {
             $this->connection = new PDO($dsn, $this->username, $this->password);
             if ($this->type == 'mysql') {
                 $this->connection->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
             }
         } catch (PDOException $e) {
             $this->connection = FALSE;
         }
     }
     if ($this->extension == 'sqlite') {
         $this->connection = sqlite_open($this->database);
     }
     if ($this->extension == 'mssql') {
         $separator = fCore::checkOS('windows') ? ',' : ':';
         $this->connection = mssql_connect($this->port ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password);
         if ($this->connection !== FALSE && mssql_select_db($this->database, $this->connection) === FALSE) {
             $this->connection = FALSE;
         }
     }
     if ($this->extension == 'mysql') {
         if (substr($this->host, 0, 5) == 'sock:') {
             $host = substr($this->host, 4);
         } elseif ($this->port) {
             $host = $this->host . ':' . $this->port;
         } else {
             $host = $this->host;
         }
         $this->connection = mysql_connect($host, $this->username, $this->password);
         if ($this->connection !== FALSE && mysql_select_db($this->database, $this->connection) === FALSE) {
             $this->connection = FALSE;
         }
     }
     if ($this->extension == 'mysqli') {
         if (substr($this->host, 0, 5) == 'sock:') {
             $this->connection = mysqli_connect('localhost', $this->username, $this->password, $this->database, $this->port, substr($this->host, 5));
         } elseif ($this->port) {
             $this->connection = mysqli_connect($this->host, $this->username, $this->password, $this->database, $this->port);
         } else {
             $this->connection = mysqli_connect($this->host, $this->username, $this->password, $this->database);
         }
     }
     if ($this->extension == 'oci8') {
         $this->connection = oci_connect($this->username, $this->password, $this->host . ($this->port ? ':' . $this->port : '') . '/' . $this->database, 'AL32UTF8');
     }
     if ($this->extension == 'odbc') {
         $this->connection = odbc_connect(substr($this->database, 4), $this->username, $this->password);
     }
     if ($this->extension == 'pgsql') {
         $connection_string = "dbname='" . addslashes($this->database) . "'";
         if ($this->host && $this->host != 'sock:') {
             $connection_string .= " host='" . addslashes($this->host) . "'";
         }
//.........这里部分代码省略.........
开发者ID:jsuarez,项目名称:MyDesign,代码行数:101,代码来源:fDatabase.php

示例2: connectToDatabase

 /**
  * Connects to the database specified if no connection exists
  * 
  * @return void
  */
 private function connectToDatabase()
 {
     // Don't try to reconnect if we are already connected
     if ($this->connection) {
         return;
     }
     // Establish a connection to the database
     if ($this->extension == 'pdo') {
         $username = $this->username;
         $password = $this->password;
         if ($this->type == 'db2') {
             if ($this->host === NULL && $this->port === NULL) {
                 $dsn = 'ibm:DSN:' . $this->database;
             } else {
                 $dsn = 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';';
                 $dsn .= 'PORT=' . ($this->port ? $this->port : 60000) . ';';
                 $dsn .= 'PROTOCOL=TCPIP;UID=' . $username . ';PWD=' . $password . ';';
                 $username = NULL;
                 $password = NULL;
             }
         } elseif ($this->type == 'mssql') {
             $separator = fCore::checkOS('windows') ? ',' : ':';
             $port = $this->port ? $separator . $this->port : '';
             $driver = fCore::checkOs('windows') ? 'mssql' : 'dblib';
             $dsn = $driver . ':host=' . $this->host . $port . ';dbname=' . $this->database;
         } elseif ($this->type == 'mysql') {
             if (substr($this->host, 0, 5) == 'sock:') {
                 $dsn = 'mysql:unix_socket=' . substr($this->host, 5) . ';dbname=' . $this->database;
             } else {
                 $port = $this->port ? ';port=' . $this->port : '';
                 $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . $port;
             }
         } elseif ($this->type == 'oracle') {
             $port = $this->port ? ':' . $this->port : '';
             $dsn = 'oci:dbname=' . $this->host . $port . '/' . $this->database . ';charset=AL32UTF8';
         } elseif ($this->type == 'postgresql') {
             $dsn = 'pgsql:dbname=' . $this->database;
             if ($this->host && $this->host != 'sock:') {
                 $dsn .= ' host=' . $this->host;
             }
             if ($this->port) {
                 $dsn .= ' port=' . $this->port;
             }
         } elseif ($this->type == 'sqlite') {
             $dsn = 'sqlite:' . $this->database;
         }
         try {
             $this->connection = new PDO($dsn, $username, $password);
             if ($this->type == 'mysql') {
                 $this->connection->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
             }
         } catch (PDOException $e) {
             $this->connection = FALSE;
         }
     }
     if ($this->extension == 'sqlite') {
         $this->connection = sqlite_open($this->database);
     }
     if ($this->extension == 'ibm_db2') {
         $username = $this->username;
         $password = $this->password;
         if ($this->host === NULL && $this->port === NULL) {
             $connection_string = $this->database;
         } else {
             $connection_string = 'DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';';
             $connection_string .= 'PORT=' . ($this->port ? $this->port : 60000) . ';';
             $connection_string .= 'PROTOCOL=TCPIP;UID=' . $this->username . ';PWD=' . $this->password . ';';
             $username = NULL;
             $password = NULL;
         }
         $options = array('autocommit' => DB2_AUTOCOMMIT_ON, 'DB2_ATTR_CASE' => DB2_CASE_LOWER);
         $this->connection = db2_connect($connection_string, $username, $password, $options);
     }
     if ($this->extension == 'mssql') {
         $separator = fCore::checkOS('windows') ? ',' : ':';
         $this->connection = mssql_connect($this->port ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password, TRUE);
         if ($this->connection !== FALSE && mssql_select_db($this->database, $this->connection) === FALSE) {
             $this->connection = FALSE;
         }
     }
     if ($this->extension == 'mysql') {
         if (substr($this->host, 0, 5) == 'sock:') {
             $host = substr($this->host, 4);
         } elseif ($this->port) {
             $host = $this->host . ':' . $this->port;
         } else {
             $host = $this->host;
         }
         $this->connection = mysql_connect($host, $this->username, $this->password, TRUE);
         if ($this->connection !== FALSE && mysql_select_db($this->database, $this->connection) === FALSE) {
             $this->connection = FALSE;
         }
         if ($this->connection && function_exists('mysql_set_charset') && !mysql_set_charset('utf8', $this->connection)) {
             throw new fConnectivityException('There was an error setting the database connection to use UTF-8');
         }
//.........这里部分代码省略.........
开发者ID:JhunCabas,项目名称:material-management,代码行数:101,代码来源:fDatabase.php

示例3: connect

 /**
  * Connects to the database specified, if no connection exists
  *
  * This method is only intended to force a connection, all operations that
  * require a database connection will automatically call this method.
  *
  * @throws fAuthorizationException  When the username and password are not accepted
  *
  * @return void
  */
 public function connect()
 {
     // Don't try to reconnect if we are already connected
     if ($this->connection) {
         return;
     }
     $connection_error = FALSE;
     $authentication_error = FALSE;
     $database_error = FALSE;
     $errors = NULL;
     // Establish a connection to the database
     if ($this->extension == 'pdo') {
         $username = $this->username;
         $password = $this->password;
         $options = array();
         if ($this->timeout !== NULL && $this->type != 'sqlite' && $this->type != 'mssql') {
             $options[PDO::ATTR_TIMEOUT] = $this->timeout;
         }
         if ($this->type == 'db2') {
             if ($this->host === NULL && $this->port === NULL) {
                 $dsn = 'ibm:DSN:' . $this->database;
             } else {
                 $dsn = 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';';
                 $dsn .= 'PORT=' . ($this->port ? $this->port : 60000) . ';';
                 $dsn .= 'PROTOCOL=TCPIP;UID=' . $username . ';PWD=' . $password . ';';
                 if ($this->timeout !== NULL) {
                     $dsn .= 'CONNECTTIMEOUT=' . $this->timeout . ';';
                 }
                 $username = NULL;
                 $password = NULL;
             }
         } elseif ($this->type == 'mssql') {
             $separator = fCore::checkOS('windows') ? ',' : ':';
             $port = $this->port ? $separator . $this->port : '';
             $driver = fCore::checkOs('windows') ? 'mssql' : 'dblib';
             $dsn = $driver . ':host=' . $this->host . $port . ';dbname=' . $this->database;
             // This driver does not support timeouts so we fake it here
             if ($this->timeout !== NULL) {
                 fCore::startErrorCapture();
                 $resource = fsockopen($this->host, $this->port ? $this->port : 1433, $errno, $errstr, $this->timeout);
                 $errors = fCore::stopErrorCapture();
                 if ($resource !== FALSE) {
                     fclose($resource);
                 }
             }
         } elseif ($this->type == 'mysql') {
             if (substr($this->host, 0, 5) == 'sock:') {
                 $dsn = 'mysql:unix_socket=' . substr($this->host, 5) . ';dbname=' . $this->database;
             } else {
                 $port = $this->port ? ';port=' . $this->port : '';
                 $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . $port;
             }
         } elseif ($this->type == 'oracle') {
             $port = $this->port ? ':' . $this->port : '';
             $dsn = 'oci:dbname=' . $this->host . $port . '/' . $this->database . ';charset=AL32UTF8';
             // This driver does not support timeouts so we fake it here
             if ($this->timeout !== NULL) {
                 fCore::startErrorCapture();
                 $resource = fsockopen($this->host, $this->port ? $this->port : 1521, $errno, $errstr, $this->timeout);
                 $errors = fCore::stopErrorCapture();
                 if ($resource !== FALSE) {
                     fclose($resource);
                 }
             }
         } elseif ($this->type == 'postgresql') {
             $dsn = 'pgsql:dbname=' . $this->database;
             if ($this->host && $this->host != 'sock:') {
                 $dsn .= ' host=' . $this->host;
             }
             if ($this->port) {
                 $dsn .= ' port=' . $this->port;
             }
         } elseif ($this->type == 'sqlite') {
             $dsn = 'sqlite:' . $this->database;
         }
         try {
             if ($errors) {
                 $this->connection = FALSE;
             } else {
                 $this->connection = new PDO($dsn, $username, $password, $options);
                 if ($this->type == 'mysql') {
                     $this->connection->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
                 }
             }
         } catch (PDOException $e) {
             $this->connection = FALSE;
             $errors = $e->getMessage();
         }
     }
     if ($this->extension == 'sqlite') {
//.........这里部分代码省略.........
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:101,代码来源:fDatabase.php


注:本文中的fCore::checkOs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。