Common php technologies

Source: Internet
Author: User
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']);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.