0%

SQLServer由freetds改用odbc

SQLServer由freetds改用odbc

Docker

https://hub.docker.com/_/microsoft-mssql-server

MacOS

1
2
3
4
5
# 安装 ODBC
brew install msodbcsql mssql-tools

# 安装 sqlsrv pdo_sqlsrv
/usr/local/Cellar/php@7.2/7.2.34_3/bin/pecl install sqlsrv pdo_sqlsrv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?phpo
error_reporting(E_ALL);
set_time_limit(0);
$serverName = "192.168.36.132";
$connectionOptions = array(
//"host" => "192.168.36.132:1433",
"Database" => "test",
"UID" => "sa",
"PWD" => "1234"
);

//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);

if ($conn) {
echo "Connected!";
} else {
echo "Not Connected!";
}

try {
$conn = new PDO("sqlsrv:server=${serverName},1433;Database=${connectionOptions['Database']};ConnectionPooling=0", $connectionOptions['UID'], $connectionOptions['PWD'],
array(
//PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)
);

$stmt = $conn->query('SELECT * FROM "user"');
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>'; var_dump($row); echo '</pre>';
} catch (\Exception $e) {
echo '<pre>'; var_dump($e->getMessage()); echo '</pre>';
}
1
/usr/local/Cellar/php@7.2/7.2.34_3/bin/php sqlServer.php

参考