[ Pobierz całość w formacie PDF ]
.Destroying ObjectsYou can destroy an object with the following statement:unset($objName);Object-OrientedProgramming 14_167779 bk02ch04.qxp 12/17/07 8:09 PM Page 256256 Destroying ObjectsFor example, you can create and destroy an object of the Carclass with thefollowing statements:$myCar = new Car;unset($myCar);After $myCaris unset, the object no longer exists at all.PHP provides a method that is automatically run when an object isdestroyed.You add this method to your class and call it _ _destruct(with two underscores).For example, the following class contains a__destructmethod:class Bridge{function __destruct(){echo  The bridge is destroyed ;}}If you use the following statements, the object is created and destroyed:$bigBridge = new Bridge;unset($bigBridge);The output from these statements isThe bridge is destroyedThe output is echoed by the __destructmethod when the object is unset.The __destructmethod isn t required.It s just available for you to useif you want to execute some statements when the object is destroyed.Forexample, you might want to close some files or copy some information toyour database. 15_167779 pt03.qxp 12/17/07 8:09 PM Page 257Book IIIUsing MySQL 15_167779 pt03.qxp 12/17/07 8:09 PM Page 258Contents at a GlanceChapter 1: Introducing MySQL.259Chapter 2: Administering MySQL.269Chapter 3: Designing and Building a Database.295Chapter 4: Using the Database.319Chapter 5: Communicating with the Database from PHP Scripts.343 16_167779 bk03ch01.qxp 12/17/07 8:10 PM Page 259Chapter 1: Introducing MySQLIn This ChapterDiscovering how MySQL worksCommunicating with MySQLSecuring data stored in MySQLany dynamic Web sites require a backend database.The databaseMcan contain information that the Web pages display to the user.Or,the purpose of the database might be to store information provided by theuser.In some applications, the database both provides available informationand stores new information.MySQL, the most popular database for use in Web sites, was developed tobe fast and small, specifically for Web sites.MySQL is particularly popularfor use with Web sites that are written in PHP, and PHP and MySQL workwell together.This chapter provides an introduction to MySQL.It explains how it worksand how you can communicate with it.How MySQL WorksThe MySQL software consists of the MySQL server, several utility programsthat assist in the administration of MySQL databases, and some supportingsoftware that the MySQL server needs (but you don t need to know about).The heart of the system is the MySQL server.The MySQL server is the manager of the database system.It handles all yourdatabase instructions.For instance, if you want to create a new database,you send a message to the MySQL server that says  create a new databaseand call it newdata. The MySQL server then creates a subdirectory in itsdata directory, names the new subdirectory newdata, and puts the neces-sary files with the required format into the newdatasubdirectory.In thesame manner, to add data to that database, you send a message to the MySQLserver, giving it the data and telling it where you want the data to be added.Before you can pass instructions to the MySQL server, it must be runningand waiting for requests.The MySQL server is usually set up so that it startswhen the computer starts and continues running all the time.This is theusual setup for a Web site.However, it s not necessary to set it up to start 16_167779 bk03ch01.qxp 12/17/07 8:10 PM Page 260260 Understanding Database Structurewhen the computer starts.If you need to, you can start it manually when-ever you want to access a database.When it s running, the MySQL server lis-tens continuously for messages that are directed to it.Installing and startingthe MySQL server are discussed in Book I, Chapter 3.Understanding Database StructureMySQL is a Relational Database Management System (RDBMS).Your MySQLserver can manage many databases at the same time.In fact, many peoplemight have different databases managed by a single MySQL server.Eachdatabase consists of a structure to hold the data and the data itself.A data-base can exist without data, only a structure, be totally empty, twiddling itsthumbs and waiting for data to be stored in it.Data in a database is stored in one or more tables.You must create the data-base and the tables before you can add any data to the database.First youcreate the empty database.Then you add empty tables to the database.Database tables are organized like other tables that you re used to  in rowsand columns.Each row represents an entity in the database, such as a cus-tomer, a book, or a project [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • rozszczep.opx.pl
  •