要操作数据库,首先肯定是要先连接数据:
1. 以下是代码片断:
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath("data/phone.mdb");
$conn->Open($connstr);
下面举例从数据库中查找相关记录:
2. 以下是代码片断:
$rs = new com("ADODB.RecordSet"); //创建记录集
$rs->Open("select * from phonelist where phone='$mbnumber'",$conn,1,1);//执行查询
if(!$rs->eof){//判断是否存在匹配的记录
$id = $rs->Fields(0);
$province = $rs->Fields(2);
$city = $rs->Fields(3);
$cardtype = $rs->Fields(4);
$zipcode = $rs->Fields(5);
//打印查询结果
echo '查询结果:
';
echo '-------------------------------------------
';
echo '手机号码:'.$_POST['mbnumber'].'
';
echo '所属省份:'.iconv("gb2312","utf-8",$province->value).'
';
echo '所在城市:'.iconv("gb2312","utf-8",$city->value).'
';
echo '卡 类 型:'.iconv("gb2312","utf-8",$cardtype->value).'
';
echo '城市区号:'.iconv("gb2312","utf-8",$zipcode->value).'
';
echo '-------------------------------------------
';
}
else {
echo '没有查询到相关记录';//否则就是没有记录
}
$rs->close();//关闭对象
如果需要循环输出多条记录,写法是这样的:
3. 以下是代码片断:
$rs = new com("ADODB.RecordSet");
$rs->Open($sql,$conn,1,1);
while(!$rs->eof) {
$f = $rs->Fields(1);
echo $f->value;
$rs->MoveNext();
}
echo $rs->RecordCount(); //取记录总数

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools