本文实例讲述了PHP使用ODBC连接数据库的方法.分享给大家供大家参考.具体实现方法如下:
!DOCTYPE
html
PUBLIC
XHTML
①0
Strict//EN"
""
xmlns=""
xml:lang="en"
lang="en"
head
titlePHP
and
ODBC:
Example
①./title
meta
http-equiv="Content-Type"
content="text/html;
/
/head
body
php
$conn
=
odbc_connect(
"DRIVER={MySQL
ODBC
Driver};Server=localhost;Database=phpodbcdb",
"username",
"password");
if
(!($conn))
{
echo
"pConnection
to
DB
via
failed:
";
odbc_errormsg
($conn
);
"/p\n";
}
$sql
"SELECT
as
test";
$rs
odbc_exec($conn,$sql);
"tabletr";
"thTest/th/tr";
while
(odbc_fetch_row($rs))
$result
odbc_result($rs,"test");
"trtd$result/td/tr";
odbc_close($conn);
"/table";
/body
/html
希望本文所述对大家的php程序设计有所帮助.
①在/etc/services配置文件中添加一行启动odbc的端口,例如:
export PATH
export DLC
export PROOIBRK
export PROOIDRV
例如:
general:
data source name:自己取名
description:随便
database name:数据库的名字
user id:不填
oid/oib options:
protocol:tcp
service name:在services文件中加的merantodbc的端口名称host name:服务器的名称或ip(建议用ip,否则还要在hosts文件中加解析)database options:
database access mode:via server
service name:启动数据库的端口名(是在服务端启动数据库服务的端口名也是在服务端的services文件中)host name:启动数据库服务的机器名或ip(推荐ip)完成后应该可以连接上了
php-odbc
php-pear
PEAR是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写.它是一个PHP扩展及应用的一个代码仓库,简单地说,PEAR就是PHP的CPAN.
以上就是土嘎嘎小编为大家整理的phpodbc数据源相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!