microsoft sql server connection and configuration in php

Asked

Viewed 961 times

1

I’m trying to connect to a microsoft sql server database using php. The php version is:

PHP Version 5.6.3

and the error that gives is

Fatal error: Call to Undefined Function mssql_connect() in C: xampp htdocs Aloha.php on line 7**

I tried to use the command:

<?php  
$myServer = "server";
$myUser = "user";
$myPass = "senha";
$myDB = "mydb";

$conn = mssql_connect($myServer,$myUser,$myPass);
if (!$conn)
{ 
die('Not connected : ' . mssql_get_last_message());
} 
$db_selected = mssql_select_db($myDB, $conn);
if (!$db_selected) 
{
die ('Can\'t use db : ' . mssql_get_last_message());
} 
?>  

However it is a mistake, because it seems that my PHP is not configured to connect.

I went in php.ini and uncommented the

extension=php_mssql.dll

but it still didn’t work.

The data from phpinfo found too large to post here, so if you need any specific data ask here.

  • Vc is using microsoft’s Extension:?

  • Can’t use another API, like PDO or sqlsrv? is connection to SQL Server 7 or 2000?

  • I’m not using microsoft’s Extension, but I can use another API if you can give me a solution. I just want to make the connection (It doesn’t matter which function to use.

1 answer

2


To documentation informs that this extension is no longer available since php5.3. The recommendation is to use other Apis such as PDO or sqlsrv.

This Extension is not available anymore on Windows with PHP 5.3 or later.

Example with sqlsrv:

<?php
$servidor = 'ip ou servidor\instancia';
$db = 'test';
$usuario = 'user';
$senha = 'pass';        

$conexao = sqlsrv_connect($servidor, array('Database' => $db, 'UID' => $usuario, 'PWD' => $senha));

Related:

PDO Drivers for SQL Server

SQLSRV documentation

  • I tried using sqlsrv and gave the following error: Fatal error: Call to Undefined Function sqlsrv_connect() in C: xampp htdocs Aloha.php on line 5

  • @Felipejorge it is necessary to install the extension before, see the link PDO drivers for SQL Server, there describes how to install the two extensions.

  • http://php.net/manual/en/sqlsrv.setup.php In the manual there were no people who contributed to the configuration,

  • @Felipejorge the link of your comment is the list of functions, the other shows the installation http://answall.com/q/48078/91

  • What would be the instance?

  • @Felipejorge, sometimes the ip does not work, then you put nomeDaMaquina\noDoSQLServer

Show 1 more comment

Browser other questions tagged

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