PHP 操作Access (正确)
第一种方法:
<?php
class Access{
function getConn(){
$conn = @new COM("ADODB.Connection") or die ("ADO连接失败!");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath(__IMPL__."/db2.mdb");
$conn->Open($connstr);
return $conn;
}
}
?>
操作:
写:
$sql="insert into stu (name) values ('$name')";
$rs = $conn->Execute($sql);
读:
$rs=$conn->Execute('select * from stu');
while(!$rs->EOF){
$id=$rs->fields['id']->value;
$name=$rs->fields['name']->value;
$rs->movenext();
}
$rs->close();
$conn->close();
改:
$sql="update stu set age='".$age."' where id=".$id;
$rs=$conn->Execute($sql);
$conn->close();
删:
$sql="delete from stu where id=".$id;
$rs = $conn->Execute($sql);
$conn->close();
方法二:
<?php
class Access1{
function getConn(){
$connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath(__IMPL__."/db2.mdb");
&nbs
相关文档:
Zend-PHP编码规范
1.对于只包含PHP的文件,"?>"是不允许存在的。注释:防止末尾被意外的注入空白并显示输出。
2.缩进应使用四个空格的缩进,而不使用制表符TAB。
3.一行80个字符是比较合适的,最多为120字符。
4.行的结束符只能是标准的UNIX文本文件的换行,换行符在文件中表示为10,或16进制的 0x0A。
不要使用win ......
1.是否可以在类的外部访问一个属性是由访问修饰符来确定的。
2.从类的外部直接访问类的属性是糟糕的想法。面向对象的一个方法就是鼓励封装。在PHP中,我们一般通过__get()与__set()函数来实现对
属性的访问.如果不直接访问一个类的属性而是编写访问函数,那么可以通过一段代码执行所有访问。最初的访问函数如下所示:
cla ......
1.echo();2.print();3.die();4.printf();5.sprintf();6.print_r;7.var_dump();
1.echo()
输出多个字符串,可以多个参数,不需要圆括号,无返回值。
2.print()
只能输出一样东西,需要圆括号,有返回值,执行失败是返回flase.
3.die()
输出内容,停止程序。*多用于数据库的链接时,检验是否出错。
4.printf()
prin ......
HTML clipboard
Revealing the revolutionary fingerprint access clocking in/out system for
businesses. No more cards, no more paperwork, no more hassle! This digital
fingerprint access terminal and data logger registers finger prints for time
management plus also works as an authorized pe ......
HTML clipboard
Presidential edition double action fingerprint and access code security door
lock for your office, business or home. Get 100% safety at your entry point with
this maximum security style deadbolt double action lock.
This is one of the best and most secure methods in assuri ......