面对对象没你说的那么夸张,就是设定一个对象是猪 属性:重量,颜色 转为变量$wight 行动:走路 function onload(){ //行走的操作 } 最后就是把这个丢到一个 class pig() 这个类里面 然后 $p = new pig(); 最后$p->onload() 调用方法 其实就是针对你以前随便调用函数而言,这里是将函数封装到类里面,通过类去调用而已。
先学习java 再学php 这样蛮容易的 呵呵
<?php include_once("incClass.php");class DAO{ protected $conn; protected $table; public $errors; function __construct($table){ $this->conn = getConn(); $this->table = $table; $this->errors = false; } function get($Id){ $rs = $this->conn->execute("select * from $this->table where id =$Id"); return $rs->GetArray(); } function save($fields,$Id = false){ if (!$Id) { //insert $rs=$this->conn->Execute("SELECT * FROM $this->table"); $insertSQL = $this->conn->GetInsertSQL($rs, $fields); $this->conn->Execute($insertSQL); if ($this->conn->ErrorMsg()) $this->errors = $this->conn->ErrorMsg(); } else { //update $rs=$this->conn->Execute("SELECT * FROM $this->table where id=$Id"); $updateSQL = $this->conn->GetUpdateSQL($rs, $fields); $this->conn->Execute($updateSQL); //if ($this->conn->ErrorMsg()) $this->errors= $this->conn->ErrorMsg(); } } function delete($Id){ $sql="delete from $this->table where id=$Id"; $this->conn->execute($sql); if ($this->conn->ErrorMsg()) $this->errors= $this->conn->ErrorMsg(); } }class IdbDao extends DAO { function __construct(){ parent::__construct("idb"); } function delete($id){ $sql = "delete from amendsdetaildb where Iid=$id"; $this->conn->execute($sql); parent::delete($id); }
}class AdmendsDetailDbDAO extends DAO { function __construct(){ parent::__construct("amendsdetaildb"); } function getDetail($Iid){ $rs = $this->conn->execute("select * from $this->table where Iid =$Iid"); return $rs->GetArray(); } }class ObjectDbDAO extends DAO { function __construct(){ parent::__construct("objectdb"); } }?>
如果公司有项目做,那就用框架写一个看看,推荐使用thinkPHP。
如果没项目做,强制性的自己写一个项目,不管是什么,但是一定要用框架,因为框架是结合了OOP思路和MVC模式了的,对你的学习很有帮助的!
用你追女孩子那股不要脸的劲头,很快就入门了,而且,到手后,不会跟女朋友一样是不是耍脾气
不过,你编写php不一定非得面向对象
属性:重量,颜色
转为变量$wight
行动:走路
function onload(){
//行走的操作
}
最后就是把这个丢到一个 class pig() 这个类里面
然后 $p = new pig();
最后$p->onload() 调用方法
其实就是针对你以前随便调用函数而言,这里是将函数封装到类里面,通过类去调用而已。
<?php
include_once("incClass.php");class DAO{
protected $conn;
protected $table;
public $errors;
function __construct($table){
$this->conn = getConn();
$this->table = $table;
$this->errors = false;
}
function get($Id){
$rs = $this->conn->execute("select * from $this->table where id =$Id");
return $rs->GetArray();
}
function save($fields,$Id = false){
if (!$Id) {
//insert
$rs=$this->conn->Execute("SELECT * FROM $this->table");
$insertSQL = $this->conn->GetInsertSQL($rs, $fields);
$this->conn->Execute($insertSQL);
if ($this->conn->ErrorMsg()) $this->errors = $this->conn->ErrorMsg();
}
else {
//update
$rs=$this->conn->Execute("SELECT * FROM $this->table where id=$Id");
$updateSQL = $this->conn->GetUpdateSQL($rs, $fields);
$this->conn->Execute($updateSQL);
//if ($this->conn->ErrorMsg()) $this->errors= $this->conn->ErrorMsg();
}
}
function delete($Id){
$sql="delete from $this->table where id=$Id";
$this->conn->execute($sql);
if ($this->conn->ErrorMsg()) $this->errors= $this->conn->ErrorMsg();
}
}class IdbDao extends DAO {
function __construct(){
parent::__construct("idb");
}
function delete($id){
$sql = "delete from amendsdetaildb where Iid=$id";
$this->conn->execute($sql);
parent::delete($id);
}
}class AdmendsDetailDbDAO extends DAO {
function __construct(){
parent::__construct("amendsdetaildb");
}
function getDetail($Iid){
$rs = $this->conn->execute("select * from $this->table where Iid =$Iid");
return $rs->GetArray();
}
}class ObjectDbDAO extends DAO {
function __construct(){
parent::__construct("objectdb");
}
}?>