在
下面我們來舉一個例子,假設我們有一個在線商城,需要使用
CREATE TABLE order_info ( order_id int IDENTITY(1,1) NOT NULL, order_no varchar(30) NOT NULL, user_id int NOT NULL, total_money money NOT NULL, order_status tinyint NOT NULL, PRIMARY KEY (order_id) );
在
<?php //建立SQL Server連接 $serverName = "serverName\instance, 1433"; //服務名和端口 $connectionOptions = array( "Database" => "db_name", //數(shù)據(jù)庫名稱 "Uid" => "username", //連接用戶名 "PWD" => "password" //連接密碼 ); $conn = sqlsrv_connect($serverName, $connectionOptions); //查詢訂單表 $sql = "SELECT * from order_info"; $stmt = sqlsrv_query($conn, $sql); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { echo "OrderId: " . $row["order_id"] . ", OrderNo: " . $row["order_no"] . ", TotalMoney: " . $row["total_money"] . ", OrderStatus: " . $row["order_status"] . "<br/>"; } ?>
另外,在
<?php //建立ODBC連接 $conn = odbc_connect("Driver={SQL Server};Server=serverName\instance;Database=db_name;", "username", "password"); //查詢商品表 $sql = "SELECT * from product_info"; $rs = odbc_exec($conn, $sql); while(odbc_fetch_row($rs)) { $productId = odbc_result($rs, 1); $productName = odbc_result($rs, 2); $price = odbc_result($rs, 3); $description = odbc_result($rs, 4); echo "ProductId: " . $productId . ", ProductName: " . $productName . ", Price: " . $price . ", Description: " . $description . "<br/>"; } ?>
綜上所述,
下一篇css最新參考手冊