php sql server 配置運行

1.下載sqlserver擴展php

https://www.microsoft.com/en-us/download/details.aspx?id=20098html

解壓到mysql

\phpStudy\PHPTutorial\php\php-7.2.1-nts\extsql

 

 php.intjson


extension=php_pdo_sqlsrv_72_nts_x64.dll
extension=php_sqlsrv_72_nts_x64.dllsqlserver

安裝 msodbcsql.msi fetch

否則報錯ui

This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64this

 

代碼:sqlcon.phpspa

 $serverName = "localhost";
 $connectionInfo = array( "Database"=>"DBWMS", "UID"=>"sa", "PWD"=>"123123");
 $conn = sqlsrv_connect( $serverName, $connectionInfo );
 if( $conn === false ) {
 die( print_r( sqlsrv_errors(), true));
 }
if( $conn === false ) {
    echo "Unable to connect.";
    die(var_dump(sqlsrv_errors(), true));
}
header("Content-type: text/html; charset=utf-8");
include "sqlcon.php";

$order = $_POST['OrderNum'];
//$order = "TY20171121103652803442";
$sql = "SELECT  ID,ExpressNum,OrderNum,NetWeight,GrossWeight FROM dbo.St_UserOrder where OrderNum=  '{$order}'";

$stmt = sqlsrv_query( $conn, $sql );

$stmt = sqlsrv_fetch_array($stmt);

echo json_encode($stmt);

INSERT INTO 語句

INSERT INTO 語句用於向表格中插入新的行。

語法

INSERT INTO 表名稱 VALUES (值1, 值2,....)

咱們也能夠指定所要插入數據的列:

INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)

php經過pdo鏈接sql sqlserver

public function __construct()
{

$dbName = "sqlsrv:Server=Localhost;Database=tset";
$dbUser = "sa";

$dbPassword = "root";
$this->pdo = new PDO($dbName, $dbUser, $dbPassword);
}
對比
mysql
 $this->b =  $config;
$this->pdo = new PDO('mysql:host=Localhost;port=3301;dbname=test', "123123", "123123");
}
相關文章
相關標籤/搜索