Problems loading "mssql" in PHP

Asked

Viewed 389 times

1

I am trying to create a PHP connection with SQL Server 2008 but the server returns the following error:

Fatal error: Call to undefined function mssql_connect() 

I’ve looked in many places and everyone says to go in PHP.ini and remove the comment from the line:

extension=php_mssql.dll 

But my php.ini file does not have this line.

This is my current code, but I’ve tried several others:

<?php 
   mssql_connect("192.168.2.7", "sa", "5c@n9r1n7#@dm") or die("Não foi possível a conexão com o servidor"); 
   mssql_select_db("fd_585b0f87") or die("Não foi possível selecionar o banco de dados"); 
   mssql_close(); 
   print "Conexão OK"; 
?> 

I’ve tried that one too:

<?php 
   $server = "192.168.2.7"; 
   $banco="fd_585b0f87"; 
   $user ="sa"; 
   $senha="5c@n9r1n7#@dm"; 
   $conexao = mssql_connect($server,$user,$senha); 
   $conexao = mssql_select_db("$banco", $conexao); 

   if($conexao){ 
      echo "conexao Certa"; 
   } 
?> 

Does anyone know any way to fix that mistake?

  • 1

    Add the line in php.ini if it doesn’t exist. If it doesn’t work, you probably have to install that library. But first, try just adding the line. And this for PHP in windows, pq in linux and similar is not DLL, is SO.

  • According to the official documentation (http://php.net/manual/en/mssql.installation.php) you have to compile PHP with mssql, but this is +or- a kick, I never used m$ sql server with PHP.

  • First check if there is php_mssql.dll, if it does not exist it will not be able to load. If you are using linux it should be php_mssql.so in general it usually comes with php, create a php page and put the command: <?php phpinfo(); ? > go to this page, it will display everything your php supports, search this page for information about mssql.

  • I already used PHP with MSSQL and the same error happened, I solved it through the link below. See if it helps, if yes put as an answer not to stay only the link: http://forum.imasters.com.br/topic/395466-resolvidoerro-ao-conectar-php-a-base-dados-sql-server-2005/

1 answer

1

You may need to update the php driver to access mssql, you can download the updated driver directly on the Microsoft website (Microsoft Drivers 3.0 for PHP for SQL Server) you also have the option to use the Pdo to connect to mssql. On the php site in the mssql part there is in addition to the syntax of how to use, various comments on compatibility and information on command depreciation at the end of the page as well as solution links that may be enlightening and serve as a solution, but I believe that only update should already solve.

Make sure you have the necessary library to use mssql, that is, if the dll file or so (depending on the operating system) exists physically, create a file to read what your server supports

<?php 
phpinfo();

After creating the file check if among the supported features is present mssql. Another thing that can help a lot is to check the log file.

Browser other questions tagged

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