1

I have hosted my website on Linux server and I want to connect MS SQL database. i have used PHP in programming. I have contacted to both server provider and they helped in their extent. But my issue is not solved Can you guide me what to do. My code is below.

While I run this it is showing " could not find driver1"

Please guide me. Thanks in advance

<?php 

//echo phpinfo();

?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>testing</h1>
</body>
</html>

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'server:port';
$myDB = "DatabaseName";

// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
else
{
 echo "success";
}
?>

1 Answer 1

2
<?php

try {

    $conn = new PDO("sqlsrv:Server='server_name';Database=database_name", 'username', 'password');
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

} catch (Exception $e) {

    die(print_r($e->getMessage() ));
}

$tsql = "select * from table_name";
$getResults = $conn->prepare($tsql);
$getResults->execute();
$results = $getResults->fetchAll(PDO::FETCH_BOTH);

foreach ($results as $row) {
  echo $row['0'].' '.$row['6'];
  echo "<br>";
}


?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Rony for help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.