PHP - How to find out why mssql_connect () is not working?

I use PHP 5.2 and it usually mssql_connectworks fine, but I try to connect to the new MS SQL server and it will not connect. I probably have something wrong with the connection details or credentials, but I can’t say because I can’t get the error message.

The method mssql_connect()returns false, and the connection is not available.

mssql_get_last_message() returns nothing - so how can I explain why my connection failed?

Does anyone have any ideas?

In MySQL, I would use mysql_error- but there seems to be no equivalent for ms_sql.

[EDIT]

This question is not a duplicate of " MSSQL_CONNECT returns nothing - there is no error, but no answer " - I use php 5.2, and the code works fine for other connection details. I need to figure out how to output what a connection error is, and not a connection problem.

[EDIT2]

To clarify:

  • the extension is enabled on the server
  • The code works great for existing connection information.
  • I am using new connection details and don’t know if the hostname or password is wrong
  • I know that the code does not connect, because I check if it is connected
  • I want to find out the connection error - as you can with MySQL.

Sample code below:

    $db_connection = mssql_connect($host, $user, $pass);

    $db = mssql_select_db($dbname, $db_connection);
    if (!$db_connection) {
        echo "No connection";
        echo "connection failed because: " . ???????;
        die;
    }

What should I put instead ???????to get a connection error message?

+4
1

.

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';

// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');

if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>

, .

: http://www.php.net/manual/en/function.mssql-connect.php

-2

Source: https://habr.com/ru/post/1538838/


All Articles