search
Homephp教程php手册php odbc_connect()函数说明与实例代码

php odbc_connect()函数说明与实例代码

Jun 13, 2016 am 10:08 AM
connectodbcphpandcodefunctionExampleillustrate

连接到 ODBC odbc_connect() 函数用于连接到 ODBC 数据源。该函数有四个参数:数据源名、用户名、密码以及可选的指针类型参数。

连接到 odbc
odbc_connect() 函数用于连接到 odbc 数据源。该函数有四个参数:数据源名、用户名、密码以及可选的指针类型参数。

odbc_exec() 函数用于执行 sql 语句

$db_user="dbuser";         //定义连接用户名
$db_pass="dbpass";         //连接用户对应的密码
$dsn="dsn";          //定义dsn资料来源
if(odbc_connect($dsn,$db_user,$db_pass))    //对odbc数据源进行连接
{
  echo "成功连接到odbc数据源";      //如果成功输出内容
}
else
{
  echo "连接到odbc时出现问题!";     //如果失败输出内容
}

odbc_close_all();        //关闭所有打开的连接
echo "所有打开的odbc连接都已经被关闭!";   //执行函数后输出内容


看一个更高级的与主机连接

$db_host="server.mynetwork";        //定义主机名
$db_user="dbuser";          //定义连接用户名
$db_pass="dbpass";          //定义用户对应的密码
$dsn="dsn";           //定义dsn
$result=odbc_pconnect($dsn,$db_user,$db_pass);    //打开持续有效的odbc连接
if($result)            //对结果进行判断
{
  echo "打开一个持续有效的连接";       //成功执行输出内容
}
echo "
";
if(odbc_close($result))         //尝试关闭连接
{
  echo "关闭了?";          //如果成功关闭输出内容
}
else
{
  echo "不能关!";          //如果关闭失败输出内容
}

查询数据库教程存

数据源进行连接

$my_sql="select * from usertable";      //定义sql语句
$result=odbc_do($myconn,$my_sql);     //执行sql语句
echo odbc_num_rows($result);
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
while(odbc_fetch_row($result))
{
  echo "n";
  echo "n";
  echo "n";
  echo "n";
  echo "n";
}
echo "
id号nameaddress
".odbc_result($result,1)."".odbc_result($result,2)."".odbc_result($result,3)."
";


一些相关

odbc_free_result($result);        //释放执行sql语句占用的内存
echo "已经成功释放结果集占用的内存!";
odbc_rollback($myconn)取消所有未提交的操作
odbc_commit($myconn) //提交所有未提交的操作
odbc_autocommit($myconn,false);      //禁止自动commit
odbc_columnprivileges($myconn,"dbuser","管理员","usertable","name"); //列出给定表的列和权限
$result=odbc_columns($myconn);      //列出指定表的列的名称
echo odbc_result_all($result); 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version