SQL >> Base de Datos >  >> RDS >> Sqlserver

Conectar a SQL Server desde un Mac con PHP PDO vía FreeTDS

Esto podría ayudar: https://blog.nguyenvq.com/2010/05/16/freetds-unixodbc-rodbc-r/

Yo uso FreeTDS para llegar a Microsoft SQL Server desde Linux, y el autor de esa entrada hizo lo mismo desde un Mac. Aquí está mi /etc/freetds/freetds.conf — la única parte que añadí es el bloque de servidor XYZ al final:

[global] # TDS protocol version ; tds version = 4.2 # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) ; dump file = /tmp/freetds.log ; debug flags = 0xffff # Command and connection timeouts ; timeout = 10 ; connect timeout = 10 # If you get out-of-memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # Try setting 'text size' to a more reasonable limit text size = 64512 # Define a connection to the MSSQL server. [xyz] host = xyz port = 1433 tds version = 8.0 

[Edición del que pregunta]

Configurar FreeTDS es solo la mitad del trabajo. Una vez en su sitio, esto debería conectar desde la línea de comandos:

tsql -S xyz -U username -P password 

Luego usa dblib en lugar de mssql como tu controlador PDO:

$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd"); 

Donde $dbhost es el nombre de sección que definiste en freetds.conf.