zoukankan      html  css  js  c++  java
  • php sql server 配置运行

    1.下载sqlserver扩展

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

    解压到

    phpStudyPHPTutorialphpphp-7.2.1-ntsext

     php.int


    extension=php_pdo_sqlsrv_72_nts_x64.dll
    extension=php_sqlsrv_72_nts_x64.dll

    安装 msodbcsql.msi 

    这货要按照 64位

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

    不然报错

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

    代码:sqlcon.php

     $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");
    }
    双引号引发的
    $sth = $this->pdo->prepare('SELECT * FROM xxx WHERE id =:id');//双引号失效

    sql sever
    SELECT * FROM `pmw_St_UserOrder` WHERE id = :id


    mysql
    SELECT * FROM `pmw_St_UserOrder` WHERE id = :id


     $sth->execute(array(':id'=>'1'));


    $results = $sth->fetchAll(PDO::FETCH_ASSOC);
    
    

    $res = $db->query($sql);
    $json_arr = array();
    while ($row = $res->fetch()){
    $json_arr[]=$row;
    }
     
  • 相关阅读:
    机器学习实战
    python中的上下文管理器
    python中的参数传递
    SecureCRT在mac下无法输入中断命令
    Vim练级攻略(转)
    09_MySQL DQL_SQL99标准中的多表查询(外连接)
    08_MySQL DQL_SQL99标准中的多表查询(内连接)
    07_MySQL DQL_多表查询_等值内连接
    06_MySQL DQL_分组查询
    05_MySQL常见函数_分组函数
  • 原文地址:https://www.cnblogs.com/lemonphp/p/11120495.html
Copyright © 2011-2022 走看看