龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP 使用 ODBC 连接数据库

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
a href=http://www.ibm.com/developerworks/opensource/library/os-php-odbc/index.htmlhttp://www.ibm.com/developerworks/opensource/library/os-php-odbc/index.html/a
http://www.ibm.com/developerworks/opensource/library/os-php-odbc/index.html
<!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>
精彩图集

赞助商链接