Search code examples
phpsql-serverpdofreetds

Read-only connection to SQL Server with PDO DBLIB


Is it possible to create a read-only connection using PDO dblib, or set an attribute with a similar effect?

$connection = new PDO("dblib:host={$info['host']};dbname={$info['database']}", $info['username'], $info['password']);
$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $connection;

If not, is there some other PDO driver that would be able to do this that can connect to FreeTDS?


Solution

  • The best solution here is to create account on the db server with readonly permissions, and connect using that.