How to use PHP to connect to sql server

前端 未结 14 1968
醉梦人生
醉梦人生 2020-11-30 11:37

I want to use PHP to connect to sql server database.

I installed xampp 1.7.0(php 5.2) and SQLSRV20. I\'ve added the extensions in php.ini and I get thi

相关标签:
14条回答
  • 2020-11-30 12:12
     $server_name = "your server name";
     $database_name = "your database name";
     try
      {
       $conn = new PDO("sqlsrv:Server=$server_name;Database=$database_name;ConnectionPooling=0", "user_name", "password");
       $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    }
    catch(PDOException $e)
    {
    
        $e->getMessage();
    
    }
    
    0 讨论(0)
  • 2020-11-30 12:12

    Try this one :

    $servername = "10.85.80.229";
    $username = "root";
    $password = "pass";
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password);
    
    // Check connection
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    
    0 讨论(0)
提交回复
热议问题