Common php technologies 1. connect to the database (connect. inc. php ):
$ Dbhost = 'localhost'; // database server
$ Dbuser = 'root'; // database username
$ Dbpwd = ''; // database password
$ Dbname = ''; // database name
$ Db = new mysqli ($ dbhost, $ dbuser, $ dbpwd, $ dbname); // Create a mysql connection object
If (mysqli_connect_errno () // check whether the connection is successful
{
Echo 'Error: cocould not connect to database'. $ dbname. 'Please try again later ';
Exit;
}
$ Db-> query ("set names 'utf8';"); // sets the character set.
?>
After establishing a database connection, you can use the $ db object by referencing include ("connect. inc. php ").
2. create an xml file using DOMdocument
Xml is an important form of network data communication, and the other is json.
Create a DOMdocument object:
$ Dom = new DOMdocument ('1. 0', 'ISO-8859-1 ');
$ Dom-> formatOutput = true;
Create a root node:
$ Root = $ dom-> appendChild ($ dom-> createElement ('root '));
Add elements to the root node:
$ Root> appendChild ($ log = $ dom-> createElement ("log", $ row ['log _ content']);
Add attributes to a node:
$ Log-> appendChild (new DOMAttr ("id", $ row ['log _ id']);
$ Log-> appendChild (new DOMAttr ("title", $ row ['log _ name']);
$ Log-> appendChild (new DOMAttr ("date", $ row ['log _ date']);