Linux/PHP: Connect php7.0 with sqlserver using pdo.

PHOTO EMBED

Mon Aug 29 2022 15:51:59 GMT+0000 (UTC)

Saved by @marcopinero #php #sql

<?php

// sudo apt install php7.0-sybase


header("content-type: text/plain; charset=iso-8859-1");
ini_set("display_errors","1");
error_reporting(E_ALL);

$host="localhost";
$db="test";
$uid="sa";
$pwd="mypassword";

$query = "select top 10 * from testtable";

$conn = new PDO( "dblib:host=$host:1433;dbname=$db;", $uid, $pwd);
$stmt = $conn->prepare( $query );
$stmt->execute();

while ($r=$stmt->fetch(PDO::FETCH_ASSOC)){
	print_r($r);
}

?>
content_copyCOPY

Install PDO for php7.0, just to get connected to sqlserver