PHP Centos unixODBC
- 3 sene önce, Burak Çalışkan tarafından yazılmıştır.
- PHP Centos unixODBC için yorumlar kapalı
- CentOS,MSSQL,PHP
1 2 3 4 5 6 7 8 9 10 11 |
yum remove unixODBC* # CentOS 6 curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo # CentOS 7 curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo ACCEPT_EULA=Y yum install msodbcsql17 unixODBC unixODBC-devel |
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 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php $serverName = "your server hostname/IP, port"; $connectionOptions = array( "database" => "yourDatabase", "uid" => "yourUsername", "pwd" => "yourPassword" ); // Establishes the connection $conn = sqlsrv_connect($serverName, $connectionOptions); if ($conn === false) { die(formatErrors(sqlsrv_errors())); } // Select Query $tsql = "SELECT @@Version AS SQL_VERSION"; // Executes the query $stmt = sqlsrv_query($conn, $tsql); // Error handling if ($stmt === false) { die(formatErrors(sqlsrv_errors())); } ?> <h1> Results : </h1> <?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { echo $row['SQL_VERSION'] . PHP_EOL; } sqlsrv_free_stmt($stmt); sqlsrv_close($conn); function formatErrors($errors) { // Display errors echo "Error information: <br/>"; foreach ($errors as $error) { echo "SQLSTATE: ". $error['SQLSTATE'] . "<br/>"; echo "Code: ". $error['code'] . "<br/>"; echo "Message: ". $error['message'] . "<br/>"; } } ?> |