我知道正在尝试使用此语法从 Joomla 连接到 SQL Server。但是,这会引发一个ERROR 500
问题——从 Joomla 连接到 SQL Server 的正确语法是什么?
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$uid = "user";
$pwd = "pwd";
$DB = "database";
$serverName = "IP";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=> $DB, "ReturnDatesAsStrings" => true);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
编辑
我也尝试了这种语法,也得到了 500 错误 -->
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$option = array();
$option['driver'] = 'mssql';
$option['host'] = 'server';
$option['user'] = 'user';
$option['password'] = 'pass';
$option['database'] = 'db';
$option['prefix'] = '';
$db = JDatabase::getInstance( $option );
$query = $db->getQuery(true);
$query = "SELECT * from Test";
$db->setQuery($query);
$results = $db->loadObjectList();
编辑
以下是var_dump($db)
结果
object(JDatabaseDriverMssql)[1788]
public 'name' => string 'mssql' (length=5)
protected 'nameQuote' => null
protected 'nullDate' => string '1900-01-01 00:00:00' (length=19)
private '_database' (JDatabaseDriver) => string 'db' (length=9)
public 'serverType' => null
protected 'connection' => null
protected 'count' => int 0
protected 'cursor' => null
protected 'debug' => boolean false
protected 'limit' => int 0
protected 'log' =>
array (size=0)
empty
protected 'timings' =>
array (size=0)
empty
protected 'callStacks' =>
array (size=0)
empty
protected 'offset' => int 0
protected 'options' =>
array (size=7)
'driver' => string 'mssql' (length=5)
'host' => string 'server' (length=25)
'user' => string 'user' (length=7)
'password' => string 'pass' (length=9)
'database' => string 'db' (length=9)
'prefix' => string '' (length=0)
'select' => boolean true
protected 'sql' => null
protected 'tablePrefix' => string '' (length=0)
protected 'utf' => boolean true
protected 'utf8mb4' => boolean false
protected 'errorNum' => int 0
protected 'errorMsg' => null
protected 'transactionDepth' => int 0
protected 'disconnectHandlers' =>
array (size=0)
empty