SQLServer由freetds改用odbc
Docker
https://hub.docker.com/_/microsoft-mssql-server
MacOS
1 2 3 4 5
| brew install msodbcsql mssql-tools
/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( "Database" => "test", "UID" => "sa", "PWD" => "1234" );
$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_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
|
参考