Heim  >  Artikel  >  php教程  >  图书类程序设计初始化文件

图书类程序设计初始化文件

PHP中文网
PHP中文网Original
2016-05-25 17:15:26996Durchsuche

php代码

<!--图书类文件: class_book.php-->
<?php
	class book
	{
		private $id;
		private $name;
		private $price;
		private $author;

		function __construct()	//__construct:构造函数,建立连接
		{
			//$this->name=$name;
			//$this->price=$price;
			//$this->author=$author;
		}
		function __set($property_name,$value)
		{
			return $this->$property_name=$value;
		}
		function __get($property_name)
		{
			if(isset($this->$property_name))
			{
				return $this->$property_name;
			}
			else
			{
				return null;
			}
		}

		function add()			//添加书目
		{
			$db=new database();
			$query="INSERT INTO Computer (name,price,author) ";
			$query.="VALUES (&#39;$this->name&#39;,$this->price,&#39;$this->author&#39;)";
			$db->execute($query);
			$db=null;

		}
		function update()		//修改书目
		{
			$db=new database();
			$query="UPDATE Computer SET ";
			$query.="name=&#39;$this->name&#39;,price=$this->price,author=&#39;$this->author&#39; ";
			$query.="WHERE id=$this->id";
			$db->execute($query);
			$db=null;

		}
		function delete()		//删除书目
		{
			$db=new database();
			$query="DELETE FROM Computer WHERE id=$this->id";
			$db->execute($query);
			$db=null;
		}
		static function query($condition)				//查询书目
		{
			if($condition=="" || $condition==null)
			$condition="";
			else
			$condition="WHERE ".$condition;
			$db=new database();
			$query="SELECT * FROM Computer ".$condition;
			$arr=$db->query($query);
			return $arr;
			$db=null;

		}

	}

/*
	$b=new book("C语言",15.20,"吴强");
	$b->add();
	//$b->__set(new_author,"3");
	//$b->update();
	//$b->delete();
	//*/
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:给数组去除重复数据Nächster Artikel:socket方式发送邮件的类