本文主要介绍了php使用odbc连接数据库的方法,涉,php使用odbc操作数据库的基本技巧。希望对大家有所帮助。本文实例讲述了php使用odbc连接数据库的方法。分享给大家供大家参考。
具体实现方法如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>php and odbc: xhtml example 1</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$conn = odbc_connect(
"driver={mysql odbc 3.51 driver};server=localhost;database=phpodbcdb",
"username", "password");
if (!($conn)) {
echo "<p>connection to db via odbc failed: ";
echo odbc_errormsg ($conn );
echo "</p>\n";
}
$sql = "select 1 as test";
$rs = odbc_exec($conn,$sql);
echo "<table><tr>";
echo "<th>test</th></tr>";
while (odbc_fetch_row($rs))
{
$result = odbc_result($rs,"test");
echo "<tr><td>$result</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>
相关推荐:
php sqlserver 导入 mysql
php 数据库类 适用于 mysql sql service
超轻的 php 数据库工具包
以上就是php使用odbc连接数据库的实例的详细内容。