当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP使用ODBC连接数据库的方法

PHP使用ODBC连接数据库的方法

2018年05月10日  | 移动技术网IT编程  | 我要评论

两泽千晶,中天创实,徐杉

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网