简体   繁体   中英

install sql server drivers for php

hello everybody I'm new to coding world and I need your help I would like to connect to a server with xampp (3.2.2) and php version (7.2.4) windows 10... I have installed the drivers php_pdo_sqlsrv_72_ts_x86.dll and php_sqlsrv_72_ts_x86.dll to php.ini but also to php\\ext

and when I am trying to connect to a server with this code doesn't respond thank you very much for your time

$servename = "new";
$username = "user";
$password = "tree";
$database = "tree";
$connectionInfo =array("Database" =>"tree","USER" => "user", "PWD" => "tree");
$conn=sqlsrv_connect($servename,$connectionInfo);
if($conn)
    {echo"connection established";}
else
    {echo"connection failure";die (print_r(sqlsrv_errors(),true));}

Error message:

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()

Here you can use it with help of PDO, Please check below code and try to replace with your original data

<?php 

    $dsn = "sqlsrv:Server=**servernamehere**;Database=**Db name here**";
    $conn = new PDO($dsn, "", "");
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

    $sql = "SELECT * FROM table_name";

    foreach ($conn->query($sql) as $row) {
        print_r($row);
    } 

    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM