Difficulty with MSSQL and PHP on CentOS 6 server

1

I can not run a PHP system on the server (CentOS 6). When I try to connect to an MSSQL database the following error appears:

Call to undefined function mssql_connect()

In my localhost it works normally. The PHP version on the server is 5.4

The database connection file:

<?php
   //conexão com o sql server
   $host='*****';
   $user='****';
   $database='***';
   $pass='****';

   $con=mssql_connect($host, $user, $pass) or die ("Erro de conexão com o banco de dados")    ;
   mssql_select_db("$database") or die ("Erro ao selecionar banco de dados");
 ?>

The php.ini:

[MSSQL]
; Allow or prevent persistent links.
mssql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mssql.max_persistent = -1

; Maximum number of links (persistent+non persistent).  -1 means no limit.
mssql.max_links = -1

; Minimum error severity to display.
mssql.min_error_severity = 10

; Minimum message severity to display.
mssql.min_message_severity = 10

; Compatibility mode with old versions of PHP 3.0.
mssql.compatability_mode = Off

; Connect timeout
;mssql.connect_timeout = 5

; Query timeout
;mssql.timeout = 60

; Valid range 0 - 2147483647.  Default = 4096.
;mssql.textlimit = 4096

; Valid range 0 - 2147483647.  Default = 4096.
;mssql.textsize = 4096

; Limits the number of records in each batch.  0 = all records in one batch.
;mssql.batchsize = 0

; Specify how datetime and datetim4 columns are returned
; On => Returns data converted to SQL server settings
; Off => Returns values as YYYY-MM-DD hh:mm:ss
;mssql.datetimeconvert = On

; Use NT authentication when connecting to the server
mssql.secure_connection = Off

; Specify max number of processes. -1 = library default
; msdlib defaults to 25
; FreeTDS defaults to 4096
;mssql.max_procs = -1

; Specify client character set.
; If empty or not set the client charset from freetds.conf is used
; This is only used when compiled with FreeTDS
;mssql.charset = "ISO-8859-1"
    
asked by anonymous 15.09.2015 / 18:12

4 answers

1

Hello, how are you?

Look, let's review ...

The use of msssql_ * classes like mysql_ * is pretty old, you know? And they are no longer recommended to use them ... For use of classes of bank connections we have the PDO, which facilitates even more.

Now it depends on the level of your application, if it is something small I recommend changing the connection library for the use of PDO: link

This function is only available for Windows operating systems with PHP 5.3 or less, if you wanted to run the system on UNIX you will need to use the same PDO ...

link

  

The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and »Microsoft's SQL Server ODBC Driver for Linux.

     The PDO_SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php.ini file. The PDO_SQLSRV download comes 8 driver files, four of which are for PDO support. If you are running non-thread-safe PHP (PHP 5.3), use the php_pdo_sqlsrv_53_nts.dll file. (You should use a non-thread-safe version if you are using IIS as your web server). If you are running thread-safe PHP, use the php_pdo_sqlsrv_53_ts.dll file. Similarly for PHP 5.4, use the php_pdo_sqlsrv_54_nts.dll or php_pdo_sqlsrv_54_ts.dll depending on whether your PHP installation is non-thread-safe or thread-safe.

Needing a touch.

Edit

See if these commands install packages needed for use:

sudo apt-get install php5-sybase php5-odbc freetds-common

Hugs.

    
15.09.2015 / 18:21
2

The MSSQL module is used to access SQL Server, which had no version for Linux (< a href="https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux"> now has , see comment from gmsantos below). Even in Windows, new versions of PHP do not have them available.

You should be using an older version on your development computer.

I imagine you're using SQL Server on Windows since on Linux it still is not available on this date . Choose another database server or start using Windows as your PHP server. There is a add-on module .

    
15.09.2015 / 18:17
1

Some things have changed since posting the question to the days.

Version 4 of the SQL Server driver supports the client using Linux.

link

It is dependent on Microsoft ODBC Driver 13 for Linux and the 64-bit UnixODBC 2.3.1 driver manager to work correctly.

Only setback is that as this port is recent, some things are not working fully, such as login integrated with logged in user, Parameterized queries and others.

Driver version 4 is only compatible with versions above PHP 7. There is no driver backward compatibility for PHP 5.

  

In my localhost it works normally. The PHP version on the server is 5.4

Your localhost is probably a Windows system. Keep in mind that your development environment is similar to the production environment to avoid problems like this. One way is to use Vagrant, Docker, and the like.

    
24.08.2016 / 17:02
0

I do not know if it has been solved anymore to use this type of connection need to install a Freetds drive on the Linux server, this for this version being used (mssql_connect ())

    
24.08.2016 / 16:19