哈哈。我倒是从jsp转道php了。也不是转,只是人为php用起来简单方便,特别是php5,我想要得东西都有了。一些项目用jsp部署起来很麻烦,而且一直找不到好的jsp空间。这方面php就多了去了。
一种语言熟悉起来就好了,关键还是编程思想,我的php里面没有mysql_fetch_array($result)这样的东西,因为我学了asp以后就知道这种php特别的东西不能用,所以我学习php一开始就用adodb。还有php5面向对象特性已经非常不错了,我接触到的一些小项目完全够用的。
“万事万物皆对象”,即便很多用java的人也不一定深刻理解这句话。
不知道有没有耐心看以下代码。class TableManager {
private $tableName,$fields,$conn; public function __construct($con){
$this- >fields = array();
$this- >conn=$con;
}
public function __destruct(){ }
public function getConn(){
return $this- >conn;
}
public function getTableName(){
return ($this- >tableName);
}
public function setTableName($value){
$this- >tableName=$value;
}
public function getFields(){
return ($this- >fields);
}
public function setFields($value){
$this- >fields=$value;
}
//添加新的数据库记录
public function saveNew()
{
//一个空的纪录集合
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName);
$insertSQL = $this- >conn- >GetInsertSQL($rs, $this- >fields);
$this- >conn- >Execute($insertSQL);
}
//修改数据库记录
public function update($fieldName,$fieldValue)
{
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName." where ".$fieldName."=".$fieldValue);
$updateSQL = $this- >conn- >GetUpdateSQL($rs, $this- >fields);
$this- >conn- >Execute($updateSQL); # 更新资料库中的记录
}
public function updateRecords($sqlWhere){
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName." where ".$sqlWhere);
$updateSQL = $this- >conn- >GetUpdateSQL($rs, $this- >fields);
$this- >conn- >Execute($updateSQL); # 更新资料库中的记录
}
public function delete(){}
} class PicTableManager extends TableManager {
private $uploadFiles;//数组,保存图片路径字段.
//数组结构:$uploadFiles["uploadFieldName"]=uploadFileObj;
public function __construct($con){
parent::__construct($con);
$this- >uploadFiles=array();
}
public function __destruct(){}
public function setUploadFiles($uploadFilesV){
$this- >uploadFiles=$uploadFilesV;
}
public function getUploadFilesV(){
return $this- >uploadFilesV;
}
//上传图片方法
private function uploadFiles()
{
foreach ($this- >uploadFiles as $uploadObj) {
$uploadObj- >uploadFile();
}
}
//删除上传的图片,修改过的图片
public function delUploadedFile($fieldName,$fieldValue)
{
$conn=$this- >getConn();
$sqlString="SELECT * FROM ".$this- >getTableName()."where ".$fieldName."=".$fieldValue;
$rs=$conn- >Execute($sqlString);
foreach ($this- >uploadFiles as $uploadFieldName= >$uploadFileObj) {
if (file_exists($rs[$uploadFieldName])) {
unlink($rs[$uploadFieldName]);//删除文件
}
}
}
//覆写保存新纪录的方法
public function saveNew()
{
$this- >uploadFiles();
$tempFields=$this- >getFields();
//
foreach ($this- >uploadFiles as $uploadFieldName= >$uploadFileObj){
if (!$uploadFileObj- >uploadFile()) {
$tempFields[$uploadFieldName]=$uploadFileObj["name"];
}
}
$this- >setFields($tempFields);
parent::saveNew();
}
//覆写修改纪录的方法
public function update($fieldName,$fieldValue)
{
$this- >delUploadedFile($fieldName,$fieldValue);//删除对应纪录的有关修改过的老图片
$this- >uploadFiles();
foreach ($this- >uploadFiles as $uploadFileTableName= >$uploadFileObj){
if (!$uploadFileObj["error"]) {
$tempFields[$uploadFileTableName]=$uploadFileObj["name"];
}
}
$this- >setFields($tempFields);
parent::update($fieldName,$fieldValue);
}
public function delete()
{}
}
一种语言熟悉起来就好了,关键还是编程思想,我的php里面没有mysql_fetch_array($result)这样的东西,因为我学了asp以后就知道这种php特别的东西不能用,所以我学习php一开始就用adodb。还有php5面向对象特性已经非常不错了,我接触到的一些小项目完全够用的。
“万事万物皆对象”,即便很多用java的人也不一定深刻理解这句话。
不知道有没有耐心看以下代码。class TableManager {
private $tableName,$fields,$conn; public function __construct($con){
$this- >fields = array();
$this- >conn=$con;
}
public function __destruct(){ }
public function getConn(){
return $this- >conn;
}
public function getTableName(){
return ($this- >tableName);
}
public function setTableName($value){
$this- >tableName=$value;
}
public function getFields(){
return ($this- >fields);
}
public function setFields($value){
$this- >fields=$value;
}
//添加新的数据库记录
public function saveNew()
{
//一个空的纪录集合
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName);
$insertSQL = $this- >conn- >GetInsertSQL($rs, $this- >fields);
$this- >conn- >Execute($insertSQL);
}
//修改数据库记录
public function update($fieldName,$fieldValue)
{
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName." where ".$fieldName."=".$fieldValue);
$updateSQL = $this- >conn- >GetUpdateSQL($rs, $this- >fields);
$this- >conn- >Execute($updateSQL); # 更新资料库中的记录
}
public function updateRecords($sqlWhere){
$rs=$this- >conn- >Execute("SELECT * FROM ".$this- >tableName." where ".$sqlWhere);
$updateSQL = $this- >conn- >GetUpdateSQL($rs, $this- >fields);
$this- >conn- >Execute($updateSQL); # 更新资料库中的记录
}
public function delete(){}
} class PicTableManager extends TableManager {
private $uploadFiles;//数组,保存图片路径字段.
//数组结构:$uploadFiles["uploadFieldName"]=uploadFileObj;
public function __construct($con){
parent::__construct($con);
$this- >uploadFiles=array();
}
public function __destruct(){}
public function setUploadFiles($uploadFilesV){
$this- >uploadFiles=$uploadFilesV;
}
public function getUploadFilesV(){
return $this- >uploadFilesV;
}
//上传图片方法
private function uploadFiles()
{
foreach ($this- >uploadFiles as $uploadObj) {
$uploadObj- >uploadFile();
}
}
//删除上传的图片,修改过的图片
public function delUploadedFile($fieldName,$fieldValue)
{
$conn=$this- >getConn();
$sqlString="SELECT * FROM ".$this- >getTableName()."where ".$fieldName."=".$fieldValue;
$rs=$conn- >Execute($sqlString);
foreach ($this- >uploadFiles as $uploadFieldName= >$uploadFileObj) {
if (file_exists($rs[$uploadFieldName])) {
unlink($rs[$uploadFieldName]);//删除文件
}
}
}
//覆写保存新纪录的方法
public function saveNew()
{
$this- >uploadFiles();
$tempFields=$this- >getFields();
//
foreach ($this- >uploadFiles as $uploadFieldName= >$uploadFileObj){
if (!$uploadFileObj- >uploadFile()) {
$tempFields[$uploadFieldName]=$uploadFileObj["name"];
}
}
$this- >setFields($tempFields);
parent::saveNew();
}
//覆写修改纪录的方法
public function update($fieldName,$fieldValue)
{
$this- >delUploadedFile($fieldName,$fieldValue);//删除对应纪录的有关修改过的老图片
$this- >uploadFiles();
foreach ($this- >uploadFiles as $uploadFileTableName= >$uploadFileObj){
if (!$uploadFileObj["error"]) {
$tempFields[$uploadFileTableName]=$uploadFileObj["name"];
}
}
$this- >setFields($tempFields);
parent::update($fieldName,$fieldValue);
}
public function delete()
{}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货