Hello, ODBC(PHP) World!
Posted on 9月 30th, 2012 by cx20
ODBC
ODBC(Open Database Connectivity)は、マイクロソフト社が提唱した DBMS 接続用の API 仕様である。
DBMS の差異は ODBC ドライバによって吸収される為、ODBC の手順にしたがってプログラムを作成すれば、基本的な差異を意識せず、プログラムすることができる。
ODBCドライバ |
ファイル |
Microsoft Access Driver (*.mdb) |
ODBCJT32.DLL |
Microsoft Text Driver (*.txt; *.csv) |
ODBCJT32.DLL |
Microsoft Excel Driver (*.xls) |
ODBCJT32.DLL |
Microsoft dBase Driver (*.dbf) |
ODBCJT32.DLL |
Microsoft ODBC for Oracle |
MSORCL32.DLL |
Microsoft Paradox Driver (*.db ) |
ODBCJT32.DLL |
SQL Server |
SQLSRV32.DLL |
Microsoft Access Driver (*.mdb, *.accdb) |
ACEODBC.DLL |
SQL Server Native Client 10.0 |
SQLNCLI10.DLL |
ソースコード(PHP + ODBC + SQL Server)
<?php
$cn = odbc_connect("Driver={SQL Server};Server=(local)", "sa", "P@ssW0rd");
$rs = odbc_exec($cn, "SELECT 'Hello, ODBC World' AS Message");
while (odbc_fetch_row($rs))
{
$result = odbc_result($rs, "Message");
echo "Message", "n";
echo "-------------------n";
echo $result, "n";
}
odbc_close($cn);
?> |
<?php
$cn = odbc_connect("Driver={SQL Server};Server=(local)", "sa", "P@ssW0rd");
$rs = odbc_exec($cn, "SELECT 'Hello, ODBC World' AS Message");
while (odbc_fetch_row($rs))
{
$result = odbc_result($rs, "Message");
echo "Message", "n";
echo "-------------------n";
echo $result, "n";
}
odbc_close($cn);
?>
実行方法(Windows)
実行結果
Message
------------------
Hello, ODBC World! |
Message
------------------
Hello, ODBC World!
Tags: ODBC
Categories: ODBC, PHP