PHP中的SQL Server Connect DB常量表达式包含无效操作

问题描述 投票:0回答:1

我只是在远程Sql Server中建立了与数据库的连接,但不幸的是我遇到了此错误。

常量表达式在公共$ conn中包含无效操作=sqlsrv_connect($ serverName,$ connectionInfo);

这是我的代码:

<?php
    class Database{

        //specify database credentials
        private $serverName = "siber.com\\sqldeveloper, 1433"; //serverName\instanceName, portNumber (default is 1433)
        private $connectionInfo = array( "Database"=>"api_db", "UID"=>"SA", "PWD"=>"SiberCorshinee1123");
        public $conn = sqlsrv_connect( $serverName, $connectionInfo);



    public function getConnection(){

        $this->conn = null;

        enter code here

    }
?>
php sql-server database connection connect
1个回答
0
投票

像这样更改您的PHP脚本:

<?php
class Database {

    private $serverName = "sibernetik.com\\sqldeveloper, 1433";
    private $connectionInfo = array("Database"=>"api_db", "UID"=>"SA", "PWD"=>"SiberCorshine123");
    public $conn;

    public function getConnection(){
        $this->conn = sqlsrv_connect($this->serverName, $this->connectionInfo);

        // Additional code here, at least check the result from sqlsrv_connect().
    }
}
?>
© www.soinside.com 2019 - 2024. All rights reserved.