I have the following code that is working fine.
$dsn = 'sqlsrv:server = tcp:my_server_host,my_port; Database = my_database';
$connection = new PDO($dsn, $user, $password);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $connection->query('SELECT * FROM my_table');
But the problem is, on the production server the pdo_sqlsrv driver is not installed, and instead pdo_odbc is installed.
So how to convert the above code so that it uses the pdo_odbc driver?
I have tried with the following code.
$dsn = 'odbc:mssql;Server=my_server_host.net;Port:my_port;Database=my_database';
$connection = new PDO($dsn, $user, $passowrd);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $connection->query('SELECT * FROM my_table');
But I am getting the following error.
PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found and no default driver specified
Note: My production server is not on Windows.