1. Open connection
$this->conn = odbc_connect("Driver={SQL Server};Server=[ServerHost];Database=[InitialDatabase];", [Username], [Password]) or die("Couldn't connect to SQL Server: " . odbc_errormsg());
2. Close connection
odbc_close($this->conn);
3. Query
$query = odbc_exec($this->conn, $sql_cmd) or die("Could not execute query: $sql_cmd");
$rv = array();
while(odbc_fetch_row($query)) {
$record = array(
'col1' => odbc_result($query, 1),
'col2' => odbc_result($query, 2),
'col3' => odbc_result($query, 3),
'col4' => odbc_result($query, 4),
);
$rv[] = $record;
}
odbc_free_result($query);
沒有留言:
張貼留言