skip to Main Content

I work with xampp PHP 8.1
I’m trying to connect to SQL Server.
I downloaded the drivers, but when starting xampp I get the message (in the log file) that the drivers are not found.
I have no idea what the problem is, because the extension file path is correct, the drivers are correct, but they won’t load.

2

Answers


  1. To connect to a SQL Server database using PHP, you can use the sqlsrv_connect() function.

    an exaple:

    $serverName = "serverNameinstanceName";
    $databaseName = "databaseName";
    
    $connectionOptions = array(
      "Database" => $databaseName,
      "Uid" => "username",
      "PWD" => "password"
    );
    
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    
    if ($conn) {
      // Connection was successful
    } else {
      // Connection failed
      die(print_r(sqlsrv_errors(), true));
    }
    
    Login or Signup to reply.
  2. In order to connect with SQL database, you need your given DB username, password and PHP sqlsvr_connect() function.

    $serverName = "serverName\sqlexpress"; //serverNameinstanceName
    $connectionInfo = array( "Database"=>"dbName", "user_id"=>"your_user_name", "passwod"=>"your_password");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    if( $conn ) {
         echo "Connection was successful! <br />";
    }else{
         echo "Connection was not successful! <br />";
         die( print_r( sqlsrv_errors(), true));
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search