PHP connect SQL Server
先创建一个conn.php文档用于连接字符串,各个api都可以include它。
$server='ServerIP'; $username='username'; $password='password'; $database='Database Name'; $connstr = "Driver={SQL Server};Server=$server;Database=$database"; $conn = odbc_connect($connstr,$username,$password,SQL_CUR_USE_ODBC); |
加载之后需要写入SQL语句,可以使用odbc_fetch_row返回想要的结果
include("conn.php"); $sql="select * from tableName"; $result = @odbc_exec($conn, $sql); $arr = array(); while (odbc_fetch_row($result)) { $tmp = array(); $tmp["rtm"] = odbc_result($result,"rtm"); $tmp["zxbbh"] = odbc_result($result,"zxbbh"); array_push($arr,$tmp); } echo json_encode($arr); |