Insert Data into MSSQL DB using PHP

后端 未结 4 1050
轻奢々
轻奢々 2020-12-22 03:37

Hello there am trying to insert data into MSSQL using PHP. I have tried many times to figure out what the problem might be but i seem not to find it. Is there something am n

4条回答
  •  抹茶落季
    2020-12-22 04:31

    You can use SQLSRV Driver instead of MSSQL Driver and then try this

     "sa",  "PWD" => "Password",  "Database" => "DBname");
    $conn = sqlsrv_connect($serverName, $options);
    
    if( $conn === false )
         {
         echo "Could not connect.\n";
         die( print_r( sqlsrv_errors(), true));
         }
    
    $no = $_POST['no'];
    $name= $_POST['name'];
    
    $query = "INSERT INTO dbo.Test
            (No_,FirstName)
            VALUES(?, ?)";
    $params1 = array($no,$name);                       
    $result = sqlsrv_query($conn,$query,$params1);
    
    sqlsrv_close($conn);
    ?>
    

    This is more useful, and you can learn more here:

    https://msdn.microsoft.com/en-us/library/cc626305(v=sql.105).aspx

提交回复
热议问题