Instalación de ODBC en Linux para conexión con MSSQL
24 de noviembre de 2020Fabricación de transistores 3D
5 de diciembre de 2020MSSQL PDO
apt-get install php-pear php-dev autoconf automake libtool m4
pecl config-set php_ini /etc/php/7.2/fpm/php.ini
pecl install sqlsrv-5.8.1
pecl install pdo_sqlsrv
printf "priority=20 extension=sqlsrv.so" > /etc/php/7.2/mods-available/sqlsrv.ini
printf "priority=30 extension=pdo_sqlsrv.so" > /etc/php/7.2/mods-available/pdo_sqlsrv.ini
phpenmod -v 7.2 sqlsrv pdo_sqlsrv
systemctl restart php7.2-fpm
UNIX-ODBC
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list >/etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin" ' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin" ' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
apt-get install unixodbc-dev
SCRIPT PHP DE PRUEBA
<html><head>
<title>PHP mySQL MSSQL Test connection</title>
</head>
<body>
<?php
// Create MySQL connection
echo 'CONEXION MYSQL';
$servername = "127.0.0.1:3306";
$username = "miuser";
$password = "mipass";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die(<p>Connection failed: </p>' . mysqli_connect_error());
}
echo '<p>Connected successfully</p>';
// Create MS-SQL connection
echo 'CONEXION MS-SQL';
$serverName = '192.168.1.10';
//serverName\\instanceName
$db = 'test';
$user = 'sa';
#El adminisitrador sa u otro login y user con permisos adecuados
$pwd = 'mipass';
$connectionInfo = array( "Database"=>$db, "UID"=>$user, "PWD"=>$pwd);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn) {echo '<p>Connected successfully</p>'; } else {
echo "La conexión no se pudo establecer";
die( print_r( sqlsrv_errors(), true));
}
</body></html>
Referencias:
https://stackoverflow.com/questions/3108937/how-to-install-and-run-phpize