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


PHP sqlsrv_connect函数代码示例

本文整理汇总了PHP中sqlsrv_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP sqlsrv_connect函数的具体用法?PHP sqlsrv_connect怎么用?PHP sqlsrv_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: connectInternal

 /**
  * Establishes a connection to the database.
  * Includes php_interface/after_connect_d7.php on success.
  * Throws exception on failure.
  *
  * @return void
  * @throws \Bitrix\Main\DB\ConnectionException
  */
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     $connectionInfo = array("UID" => $this->login, "PWD" => $this->password, "Database" => $this->database, "ReturnDatesAsStrings" => true);
     if (($this->options & self::PERSISTENT) != 0) {
         $connectionInfo["ConnectionPooling"] = true;
     } else {
         $connectionInfo["ConnectionPooling"] = false;
     }
     $connection = sqlsrv_connect($this->host, $connectionInfo);
     if (!$connection) {
         throw new ConnectionException('MS Sql connect error', $this->getErrorMessage());
     }
     $this->resource = $connection;
     $this->isConnected = true;
     // hide cautions
     sqlsrv_configure("WarningsReturnAsErrors", 0);
     /** @noinspection PhpUnusedLocalVariableInspection */
     global $DB, $USER, $APPLICATION;
     if ($fn = \Bitrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
开发者ID:Satariall,项目名称:izurit,代码行数:33,代码来源:mssqlconnection.php

示例2: connect

 /**
  * Connects to a database.
  * @return void
  * @throws Dibi\Exception
  */
 public function connect(array &$config)
 {
     Helpers::alias($config, 'options|UID', 'username');
     Helpers::alias($config, 'options|PWD', 'password');
     Helpers::alias($config, 'options|Database', 'database');
     Helpers::alias($config, 'options|CharacterSet', 'charset');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         $options =& $config['options'];
         // Default values
         if (!isset($options['CharacterSet'])) {
             $options['CharacterSet'] = 'UTF-8';
         }
         $options['PWD'] = (string) $options['PWD'];
         $options['UID'] = (string) $options['UID'];
         $options['Database'] = (string) $options['Database'];
         $this->connection = sqlsrv_connect($config['host'], $options);
     }
     if (!is_resource($this->connection)) {
         $info = sqlsrv_errors();
         throw new Dibi\DriverException($info[0]['message'], $info[0]['code']);
     }
     $this->version = sqlsrv_server_info($this->connection)['SQLServerVersion'];
 }
开发者ID:ludik1,项目名称:transport_company,代码行数:30,代码来源:SqlsrvDriver.php

示例3: Query

 public function Query($Procedimiento, $RetornaDatos, $arrayValores = "")
 {
     $parametros = array();
     $NombreServidor = constant("sqlHost");
     $InfoConexion = array("UID" => constant("sqlUsuario"), "PWD" => constant("sqlContrasena"), "Database" => $this->NombreBaseDatos);
     $conn = sqlsrv_connect($NombreServidor, $InfoConexion);
     if (is_array($arrayValores)) {
         $stringInterrogacion = "(?";
         for ($i = 1; $i < count($arrayValores); $i++) {
             $stringInterrogacion .= ",?";
         }
         $stringInterrogacion .= ")";
         $Procedimiento = "{call " . $Procedimiento . " " . $stringInterrogacion . "}";
         for ($i = 0; $i < count($arrayValores); $i++) {
             array_push($parametros, array($arrayValores[$i], SQLSRV_PARAM_IN));
         }
     } else {
         $Procedimiento = "{call " . $Procedimiento . "}";
     }
     $stmt3 = sqlsrv_query($conn, $Procedimiento, $parametros);
     if ($RetornaDatos) {
         $array = array();
         while ($obj = sqlsrv_fetch_array($stmt3, SQLSRV_FETCH_ASSOC)) {
             $array[] = $obj;
         }
         return $array;
         sqlsrv_free_stmt($stmt3);
     }
     sqlsrv_close($conn);
 }
开发者ID:raicerk,项目名称:Biblioteca,代码行数:30,代码来源:Modelo.ddbb.php

示例4: connect

 private function connect()
 {
     $this->conn = sqlsrv_connect($this->server, array("Database" => $this->db, "UID" => $this->user, "PWD" => $this->pw));
     if ($this->conn === false) {
         die(print_r(sqlsrv_errors(), true));
     }
 }
开发者ID:arodriguezcnmc,项目名称:test,代码行数:7,代码来源:db_sqlsrv.php

示例5: getDbConnect

 private function getDbConnect($address, $account, $pwd, $name)
 {
     if (DB_TYPE == 'mssql') {
         return mssql_connect($address, $account, $pwd);
     }
     if (DB_TYPE == 'sqlsrv') {
         if (defined('DBITPro_Dev')) {
             $connectionInfo = array("UID" => $account, "PWD" => $pwd, "Database" => $name);
         } else {
             $connectionInfo = array("UID" => $account, "PWD" => $pwd, "Database" => $name);
         }
         $conn = sqlsrv_connect($address, $connectionInfo);
         if (false === $conn) {
             echo "Could not connect.\n";
             die(print_r(sqlsrv_errors(), true));
         }
         return $conn;
     }
     if (DB_TYPE == 'mysql') {
         $conn = mysql_connect($address, $account, $pwd);
         if (false === $conn) {
             echo "Could not connect.\n";
             die(print_r(mysql_errors(), true));
         }
         return $conn;
     }
 }
开发者ID:bciv,项目名称:COMS,代码行数:27,代码来源:sqlquery.class.php

示例6: Ymssql

 public function Ymssql($url)
 {
     $url = parse_url($url);
     // Check if SQLSRV support is present in PHP
     if (!function_exists('sqlsrv_connect')) {
         die('Unable to use the Microsoft SQL Server database because the SQLSRV extension for PHP is not installed. Check your <code>php.ini</code> to see how you can enable it.');
     }
     // Decode url-encoded information in the db connection string
     $url['user'] = urldecode($url['user']);
     // Test if database url has a password.
     $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : '';
     $url['host'] = urldecode($url['host']);
     $url['path'] = urldecode($url['path']);
     // Allow for non-standard port.
     if (isset($url['port'])) {
         $url['host'] = $url['host'] . ', ' . $url['port'];
     }
     $connectionInfo = array("Database" => substr($url['path'], 1), "UID" => $url['user'], "PWD" => $url['pass']);
     $connection = @sqlsrv_connect($url['host'], $connectionInfo);
     if (!$connection) {
         // Show error screen otherwise
         throw new Exception(print_r(sqlsrv_errors(), true));
     }
     $this->lnk = $connection;
 }
开发者ID:yunsite,项目名称:yuan-pad,代码行数:25,代码来源:Ymssql.php

示例7: getDentrix

function getDentrix()
{
    #	PHPinfo();
    $connInfo = array("Database" => "dentrix", "UID" => "jl149", "PWD" => "l3tm31n", "ReturnDatesAsStrings" => true);
    $dentrix = sqlsrv_connect("192.168.14.55,1435", $connInfo);
    return $dentrix;
}
开发者ID:JamesLeB,项目名称:Dashboard,代码行数:7,代码来源:openEOB.php

示例8: connect

 /**
  * @return false|mysqli|resource
  */
 public function connect()
 {
     try {
         if ($this->DRIVER == "sqlsrv") {
             $server_name = $this->HOST_NAME . "," . $this->PORT;
             $dbection_info = array("Database" => $this->DATABASE, "UID" => $this->USER, "PWD" => $this->PASSWORD);
             $db = sqlsrv_connect($server_name, $dbection_info);
             if ($db === false) {
                 die(print_r(sqlsrv_errors(), true));
             } else {
                 return $db;
             }
         } else {
             if ($this->DRIVER == "mysqli") {
                 $db = new mysqli($this->HOST_NAME, $this->USER, $this->PASSWORD, $this->DATABASE, $this->PORT);
                 if ($db->connect_error) {
                     die('Connect Error (' . $db->connect_errno . ') ' . $db->connect_error);
                 }
                 return $db;
             } else {
                 die("Driver not found!");
             }
         }
     } catch (Exception $e) {
         var_dump("Error: {$e->getMessage()}");
         return;
     }
 }
开发者ID:orounmoly,项目名称:php_cv,代码行数:31,代码来源:DbOperation.php

示例9: GetFacultyQuestions

function GetFacultyQuestions($groupid)
{
    include_once 'db_Connection.php';
    $conn = sqlsrv_connect($serverName, $connectionInfo);
    $questionvalues = array();
    $questions = array();
    $faculty = array();
    $facultyquestions = array();
    if ($conn) {
        //----get acadyear-------------------
        $acid = 0;
        $sqlstr = " SELECT [AcadYearID] FROM [dbo].[Groups] where [groupid]=? ";
        $params = array($groupid);
        $sqlquery = sqlsrv_query($conn, $sqlstr, $params);
        if ($sqlquery) {
            while ($row = sqlsrv_fetch_array($sqlquery, SQLSRV_FETCH_ASSOC)) {
                $acid = $row['AcadYearID'];
            }
            sqlsrv_free_stmt($sqlquery);
        }
        $sqlstr = " SELECT [questionTypeId],[value],[text] " . " FROM [dbo].[QuestionValues] " . " order by questionTypeId ";
        //  $params = array ($acid);
        $sqlquery = sqlsrv_query($conn, $sqlstr);
        if ($sqlquery) {
            while ($row = sqlsrv_fetch_object($sqlquery)) {
                $questionvalues[] = $row;
            }
            sqlsrv_free_stmt($sqlquery);
        }
        //----get question array-------------------
        $sqlstr = " SELECT [QuestionID],[QueastionText],[questionType],[maxmark],-1 as mark,'' as description " . " FROM [dbo].[Questions] " . " where [QuestionLecturer]=0 " . " and [Acadyear]=? ";
        $params = array($acid);
        $sqlquery = sqlsrv_query($conn, $sqlstr, $params);
        if ($sqlquery) {
            while ($row = sqlsrv_fetch_object($sqlquery)) {
                $row->questionValues = array();
                foreach ($questionvalues as &$questValue) {
                    if ($questValue->questionTypeId === $row->questionType) {
                        array_push($row->questionValues, $questValue);
                    }
                }
                $questions[] = $row;
            }
            sqlsrv_free_stmt($sqlquery);
        }
        //----get faculty-------------------
        $sqlstr = " SELECT [FacultyID],[FacultyName] FROM [dbo].[Groups] " . " where [groupid]=? ";
        $params = array($groupid);
        $sqlquery = sqlsrv_query($conn, $sqlstr, $params);
        if ($sqlquery) {
            while ($row = sqlsrv_fetch_object($sqlquery)) {
                $row->quests = $questions;
                $faculty[] = $row;
            }
            $facultyquestions = array("result" => 0, "data" => $faculty);
        }
        sqlsrv_close($conn);
    }
    return $facultyquestions;
}
开发者ID:Nata12,项目名称:SocHarcum,代码行数:60,代码来源:getFacultyQuestions.php

示例10: AttemptConnection

 public function AttemptConnection()
 {
     if (empty($this->type)) {
         return false;
     } elseif ($this->type == "MySQL") {
         $this->connection = mysqli_connect($this->address, $this->username, $this->password, $this->database);
         if (!$this->connection) {
             $this->lastErrorMessage = "Error: Unable to connect to MySQL." . PHP_EOL . "Debugging errno: " . mysqli_connect_errno() . PHP_EOL . "Debugging error: " . mysqli_connect_error() . PHP_EOL;
             return false;
         }
         //SQL Server
     } elseif ($this->type == "MSSQL") {
         $connectionInfo = array("Database" => $this->database, "UID" => $this->username, "PWD" => $this->password);
         $this->connection = sqlsrv_connect($this->address, $connectionInfo);
         if (!$this->connection) {
             $errorString = "";
             if (($errors = sqlsrv_errors()) != null) {
                 foreach ($errors as $error) {
                     $errorString .= PHP_EOL . "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
                     $errorString .= "SQLSTATE: " . $error['SQLSTATE'] . PHP_EOL;
                     $errorString .= "code: " . $error['code'] . PHP_EOL;
                     $errorString .= "message: " . $error['message'] . PHP_EOL;
                 }
             }
             $this->lastErrorMessage = "Error: Unable to connect to SQL Server." . PHP_EOL . "Debugging error: " . $errorString . PHP_EOL;
             $this->lastError = $errorString;
             return false;
         }
     }
     return $this->connection;
 }
开发者ID:Blue-Kachina,项目名称:Helping-Developers-With-Class,代码行数:31,代码来源:DBConnection.php

示例11: connect

 public function connect($url, $username, $password)
 {
     if (!function_exists('sqlsrv_connect')) {
         return false;
     }
     $tmp = parse_url($url);
     if (!array_key_exists('scheme', $tmp) || $tmp['scheme'] != 'sqlserver') {
         throw new DataAccessException("데이터베이스 스키마가 드라이버와 일치하지 않습니다.");
     }
     $arrTmp = explode(';', $tmp['host']);
     $arrOptions = array();
     foreach ($arrTmp as $option) {
         if (trim($option) == '') {
             continue;
         }
         if (substr_count($option, '=') > 0) {
             list($k, $v) = explode('=', $option, 2);
             $arrOptions[$k] = $v;
         } else {
             $arrOptions['host'] = $option;
         }
     }
     if (!array_key_exists('DatabaseName', $arrOptions)) {
         throw new DataAccessException("데이터베이스 명이 누락되었습니다.");
     }
     $characterSet = !array_key_exists('CharacterSet', $arrOptions) ? 'UTF-8' : $arrOptions['CharacterSet'];
     $this->_host = $arrOptions['host'];
     try {
         $this->_conn = sqlsrv_connect($this->_host, array("Database" => $arrOptions['DatabaseName'], "UID" => $username, "PWD" => $password, "CharacterSet" => $characterSet));
     } catch (Exception $ex) {
         throw $ex;
     }
     $this->_connected = $this->_conn ? true : false;
     return $this->_connected;
 }
开发者ID:autoset,项目名称:santorini,代码行数:35,代码来源:MssqlDriver.class.php

示例12: dbcall

function dbcall()
{
    session_start();
    $seubid = (string) session_id();
    $server = "bamsql2";
    $options = array("UID" => "genes", "PWD" => "Genes12", "Database" => "genes");
    $conn = sqlsrv_connect($server, $options);
    if ($conn === false) {
        die("<pre>" . print_r(sqlsrv_errors(), true));
    }
    $rno = $_POST['Rnumber'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $sql = "insert INTO dbo.contactinfo values('{$rno}','{$name}','{$email}','{$gender}')";
    $query = sqlsrv_query($conn, $sql);
    if ($query === false) {
        exit("<pre>" . print_r(sqlsrv_errors(), true));
    }
    #while ($row = sqlsrv_fetch_array($query))
    # {  echo "<p>Hello, $row[ascore]!</p>";
    #}
    sqlsrv_free_stmt($query);
    sqlsrv_close($conn);
}
开发者ID:vivek8943,项目名称:RawlsGACode,代码行数:25,代码来源:Guessdemo.php

示例13: connect

 public function connect($parameters, $selectDB = false)
 {
     // Disable default warnings as errors behaviour for sqlsrv to keep it in line with mssql functions
     if (ini_get('sqlsrv.WarningsReturnAsErrors')) {
         ini_set('sqlsrv.WarningsReturnAsErrors', 'Off');
     }
     $charset = isset($parameters['charset']) ? $parameters : 'UTF-8';
     $multiResultSets = isset($parameters['multipleactiveresultsets']) ? $parameters['multipleactiveresultsets'] : true;
     $options = array('CharacterSet' => $charset, 'MultipleActiveResultSets' => $multiResultSets);
     if (!(defined('MSSQL_USE_WINDOWS_AUTHENTICATION') && MSSQL_USE_WINDOWS_AUTHENTICATION == true) && empty($parameters['windowsauthentication'])) {
         $options['UID'] = $parameters['username'];
         $options['PWD'] = $parameters['password'];
     }
     // Required by MS Azure database
     if ($selectDB && !empty($parameters['database'])) {
         $options['Database'] = $parameters['database'];
     }
     $this->dbConn = sqlsrv_connect($parameters['server'], $options);
     if (empty($this->dbConn)) {
         $this->databaseError("Couldn't connect to SQL Server database");
     } elseif ($selectDB && !empty($parameters['database'])) {
         // Check selected database (Azure)
         $this->selectedDatabase = $parameters['database'];
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-mssql,代码行数:25,代码来源:SQLServerConnector.php

示例14: connect

 public function connect()
 {
     if ($this->_connection) {
         return;
     }
     // Extract the connection parameters, adding required variabels
     $mssql_config = $this->_config['connection'] + array('Database' => '', 'Server' => '', 'UID' => '', 'PWD' => '', 'ConnectionPooling' => FALSE, 'CharacterSet' => 'UTF-8');
     // Extract the Server name
     $server = $mssql_config['Server'];
     // Prevent this information from showing up in traces
     unset($mssql_config['Server'], $this->_config['connection']['UID'], $this->_config['connection']['PWD']);
     // If any illegal properties is in $mssql_config, sqlsrv_connect won't connect
     unset($mssql_config['hostname'], $mssql_config['database'], $mssql_config['username'], $mssql_config['password'], $mssql_config['persistent']);
     try {
         // Create a connection
         $this->_connection = sqlsrv_connect($server, $mssql_config);
         $errors = sqlsrv_errors(SQLSRV_ERR_ALL);
         if ($this->_connection === FALSE) {
             throw new Database_Sqlsrv_Exception(':error, :sqlstate', array(':error' => $errors[0]['message'], ':sqlstate' => $errors[0]['SQLSTATE']), $errors[0]['code']);
         }
     } catch (ErrorException $e) {
         $errors = sqlsrv_errors(SQLSRV_ERR_ALL);
         throw new Database_Sqlsrv_Exception(':error, :sqlstate', array(':error' => $errors[0]['message'], ':sqlstate' => $errors[0]['SQLSTATE']), $errors[0]['code']);
     }
     // \xFF is a better delimiter, but the PHP driver uses underscore
     $this->_connection_id = sha1($server . '_' . $mssql_config['UID'] . '_' . $mssql_config['PWD']);
 }
开发者ID:JustLikeIcarus,项目名称:kohana-database-sqlsrv,代码行数:27,代码来源:core.php

示例15: OpenConnection

 function OpenConnection()
 {
     global $mysqlAuthentication;
     global $sqlserverAuthentication;
     $host = null;
     $options = null;
     if (isset($mysqlAuthentication)) {
         $host = $mysqlAuthentication["host"];
         $options = $mysqlAuthentication;
     }
     if ($this->databaseType == 'mySql' || $this->databaseType == 'both') {
         $this->mysqlConnection = @mysql_connect($host, $options["username"], $options["password"]);
     }
     if (isset($this->mysqlConnection)) {
         @mysql_set_charset("utf8");
         @mysql_select_db($options["database"], $this->mysqlConnection);
     }
     if (isset($sqlserverAuthentication)) {
         $host = $sqlserverAuthentication["host"];
         $options = array("Database" => $sqlserverAuthentication["database"], "CharacterSet" => "UTF-8", "UID" => $sqlserverAuthentication["username"], "PWD" => $sqlserverAuthentication["password"]);
     }
     if ($this->databaseType == 'sqlServer' || $this->databaseType == 'both') {
         $this->sqlserverConnection = sqlsrv_connect($host, $options);
     }
 }
开发者ID:renatosans,项目名称:contratos,代码行数:25,代码来源:DataConnector.php


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