0
$conn =  sqlsrv_connect( "192.168.1.6", 
                          array('Database' =>"epromis_test", 
                                "UID"=>"php_test",
                                "PWD"=>"phptest@123") );
if   ($conn)     
{
    echo   "sucess";
} 
else     
{
    echo    "failed";
}

Why I failed to connect the database?

thanks in advance

4
  • Hello, welcome to SO! Try to improve your post and make it readable as other posts on site. Commented Aug 15, 2018 at 6:21
  • Is mixed auth mode enabled on the server? Are you able to connect to the server using this credentials through SSMS, for instance? Commented Aug 15, 2018 at 6:53
  • What does print_r( sqlsrv_errors(), true); output? Commented Aug 15, 2018 at 8:04
  • Connection strings are often tricky, because the format and structure of connection strings changes over time with new versions of MySQL and of PHP. This means that the examples from the book or article that you are learning from are often out of date. It also means that we can't give you the right format without knowing exactly which version of PHP and MySQL you are using. However, don't despair: there's a wonderful source of information at connectionstrings.com/mysql. That website will give you the right structure to use for your particular setup. Commented Aug 15, 2018 at 9:35

1 Answer 1

1

Here is link to very good php documentation http://php.net/manual/en/function.sqlsrv-connect.php. I think you need to escape your @ symbol in password. @ becomes &commat. link on how to pass special chars https://brajeshwar.github.io/entities/

     <?php
        $serverName = "serverName\\sqlexpress"; //serverName\instanceName
        $connectionInfo = array( "Database"=>"epromis_test", "UID"=>"php_test", "PWD"=>"phptest&commat123");
        $conn = sqlsrv_connect( $serverName, $connectionInfo);

        if( $conn ) {
             echo "Connection established.<br />";
        }else{
             echo "Connection could not be established.<br />";
             die( print_r( sqlsrv_errors(), true));
        }
        ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.