How to connect PHP and MS SQL server 2019 (ok)

https://www.youtube.com/watch?v=PtM1kuSQLlQ

Đọc thêm ở đây để sử dụng pdo

https://docs.microsoft.com/en-us/sql/connect/php/example-application-sqlsrv-driver?view=sql-server-ver15

Đọc thêm: https://docs.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-on-iis/install-the-sql-server-driver-for-php

Đọc thêm: Create PHP apps using SQL Server on Windows

https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows/step/2.html

C:\xampp\htdocs\create\phpsql.php

<?php
    $serverName = "localhost";
    $connectionOptions = array(
        "Database" => "SampleDB",
        "Uid" => "test",
        "PWD" => "lionel123"
    );
    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionOptions);

    if($conn) {
        echo "Connected!";
    }else {
    	echo 'ggggggg';
    }
?>

Cấu hinh file php.ini thê này đây

extension=php_pdo_sqlsrv_74_ts.dll
extension=php_sqlsrv_74_ts.dll

Kết hợp với bài này ta có thê tạo được dạng CRUD :))

https://app.gitbook.com/@windows/s/windows10/create-php-apps-using-sql-server-on-windows-ok

sqlcmd -S localhost -U test -P lionel123 -d SampleDB -Q "CREATE SCHEMA TestSchema;"
sqlcmd -S localhost -U test -P lionel123 -d SampleDB -Q "CREATE TABLE TestSchema.Employees (Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY, Name NVARCHAR(50), Location NVARCHAR(50));"
sqlcmd -S localhost -U test -P lionel123 -d SampleDB -Q "INSERT INTO TestSchema.Employees (Name, Location) VALUES (N'Jared', N'Australia'), (N'Nikita', N'India'), (N'Tom', N'Germany');"
sqlcmd -S localhost -U test -P lionel123 -d SampleDB -Q "SELECT * FROM TestSchema.Employees;"

Last updated