Difficulty with MSSQL and PHP on Centos 6 server

Asked

Viewed 1,278 times

0

I cannot run a PHP system on the server (Centos 6). When I try to connect to a MSSQL database the following error appears:

Call to undefined function mssql_connect()

My localhost works normally. The PHP version on the server is 5.4

The file connecting to the bank:

<?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");
 ?>

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"
  • The functions mssql_*() no longer exist

  • @Jéfersonbueno, which function I use then to connect with SQL Server?

  • You have SQL Server in the Hundreds?

  • No. But the database I need to connect to is on a Windows server and my system needs to be on the Centos server

  • @Amandalima in UNIX environment, in the case of Ubuntu I use PDO only. Try running these commands: sudo apt-get install php5-Sybase php5-odbc freetds-common

  • @juniorb2ss, the Centos package manager is YUM. php5-Sybase is not available in repositories. I’ll look for these packages some other way, thanks for the tip.

  • Truth @amandaLima did not pay attention to this detail, I only use Ubuntu. It will have to be by RPM. See if it helps you: http://www.dicas-l.com.br/arquivo/mssql_com_php_no_centos_5.4.php

  • Which version does Sqlserver use?

  • @rray is SQL Server 2008. I could not connect via PDO tbm no. :(

  • Amanda, I recently had to make a connection to SQL SERVER using the mssql_connect() function. That’s what you need?

  • Yes, that’s what I needed, I already got :) The problem was the PHP version installed. I changed the version and it worked well

Show 6 more comments

4 answers

2

  • Strange... on my development computer, the PHP version is 5.6 and the Fedora operating system. It worked perfectly.

  • This is even stranger, because this version does not have this module and has no way to work SQL Server on Linux. Do you have SQL Server installed on your computer? If not, how is it working?

  • I haven’t installed it. SQL Server is on a Windows server. However, my system must be hosted on a Centos server. I thought it would work normally because my localhost works.

  • @bigown the latest version of the driver is available for Linux https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux

  • @gmsantos dei an improved.

1


Hello, all good?

Look, let’s look at it...

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

It now depends on the level of your application, if it is something small recommend to change the connection library for the use of PDO: http://php.net/manual/en/class.pdo.php

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

http://php.net/manual/en/ref.pdo-sqlsrv.php

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.

In need of a touch.

Edit

See if these commands install the packages needed for use:

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

Hugs.

  • It’s going to be kind of hard for her to use SQL Server on Linux, right? So PDO Udo doesn’t magically solve the problem. In addition to using PDO when it is certain that the database to be used is a specific one is an exaggeration.Precisely for small, simple systems that will not use various types of databases, the use of PDO is not recommended.

  • @Bigown can use UNIX environment connection for SQL Server driver in a windows environment or as for example Amazon RDS. Do not limit yourself. We have several applications in Unix environment that recover data from MSSQL. Their argument was little flaw.

  • But she’s not wearing those things, Stick to the question asked.

  • The error is due to the lack of function, certainly if it is running application in UNIX environment trying to connect in MSSQL means that certainly the connection is external. I suggested the use of PDO because if it is trying to make a connection with external MSSQL, of course, it will work properly, where this error?

  • "No. But the database I need to connect to is on a Windows server and my system needs to be on the server with Centos" I think ends here.

  • She wrote it now. When you wrote it, you didn’t have this information.

Show 2 more comments

1

Some things have changed from the question post to the days.

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

https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux

It has as dependence the Microsoft ODBC Driver 13 for Linux and the 64-bit Unixodbc 2.3.1 driver manager to function properly.

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

Version 4 of the driver is only compatible with versions above PHP 7. There is no backward compatibility of the driver for PHP 5.

My localhost 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 with the production environment to avoid problems like this. One way is to use Vagrant, Docker and the like for this.

  • My localhost is Fedora, not windows. Edora is very similar to Centos.

0

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

  • The link for it would help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.