tailieunhanh - PHP 5 Recipes A Problem-Solution Approach PHẦN 10

Bạn đang gần đến điểm mà bạn có thể mã một blog đơn giản. Bước tiếp theo là tạo ra một dự án. Làm điều này bằng cách cách nhấn vào biểu tượng New Project, mà là ở phía trên bên trái của thanh công cụ Eclipse (xem hình 1-18). | 590 15-13 PROJECT GOING FROM MYSQL TO XML AND FROM XML TO MYSQL fwrite file t t tstructure n Start an array of names. narr array while fdata mysql_fetch_assoc fquery narr fdata Field fwrite file t t t tcolumn n fwrite file t t t t Field . fdata Field . Field n fwrite file t t t t Type . fdata Type . Type n fwrite file t t t t Null . fdata Null . Null n fwrite file t t t t Key . fdata Key . Key n fwrite file t t t t Default . fdata Default . Default n fwrite file t t t t Extra . fdata Extra . Extra n fwrite file t t t tcolumn n fwrite file t t tstructure n Now show the data. if dquery mysql_query SELECT FROM . tdata 0 . if mysql_num_rows dquery 0 fwrite file t t tdata n Start a counter. while ddata mysql_fetch_assoc dquery fwrite file t t t trow n fcounter 0 while ele each ddata fwrite file t t t t t . narr fcounter . . ele value . . narr fcounter . n fcounter fwrite file t t t trow n fwrite file t t tdata n else echo mysql_error else echo mysql_error fwrite file t table n else echo mysql_error 15-13 PROJECT GOING FROM MYSQL TO XML AND FROM XML TO MYSQL 591 fwrite file db else throw new exception Sorry could not open the file for writing. catch exception e echo e- getmessage Function to drop a database be careful with this one . public function dropdb thedb try if mysql_query DROP DATABASE thedb this- db exceptionstring Error dropping database thedb br exceptionstring . mysql_errno . . mysql_error throw new exception exceptionstring catch exception e echo e- getmessage Function to close the database link. public function __destruct try if mysql_close this- db exceptionstring Error closing connection br exceptionstring . mysql_errno . . mysql_error throw new exception exceptionstring catch exception e echo e- getmessage Create a new instance of the class. myconverter new xmlconverter localhost apress testing Then convert the database into XML. myconverter- mysqltoxml cds Then drop the database to prove it works. myconverter- dropdb cds Now completely .