关于析构函数的一个问题

TheDean 2015-08-20 04:14:32

<?php

class test{
public $id;
public $name;
public $mobile;
public $regtime;

function __construct(){

@$conn=mysql_connect('localhost','root','123456789');
$db=mysql_select_db('design');
$res=mysql_query("select * from user where `id`=1");
$data=mysql_fetch_assoc($res);
$this->id=$data['id'];
$this->name=$data['name'];
$this->mobile=$data['mobile'];
$this->regtime=$data['regtime'];
}

function __destruct(){
mysql_query("update user set `regtime`='{$this->regtime}',`mobile`='{$this->mobile}',`name`='{$this->name}' where `id`='{$this->id}' LIMIT 1");
}
}
class Page{
function index(){
$user1 = new test();
$user1->name='tom';

$this->test();

}

function test(){
$user2= new test();
$user2 ->mobile='333333333';
}

}

$Page=new Page();
$Page->index();


这是看慕课视频设计模式中的一个例子,为什么$user2 ->mobile='333333333';这句话是不会插进数据库的?
...全文
58 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧