PHP Data Access

Source: Internet
Author: User

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?php//Build a connection to create a Connection object $db = new mysqli ("localhost", "root", "123", "mydb");//Determine if error/*if (Mysqli_connect_error ()) {echo "Connection Failed!    "; Exit;} */mysqli_connect_error () Die ("Connection Failed"): "";//write SQL statement $sql = "SELECT * from Info";//Execute SQL statement, return result set Object $reslut = $db->query ( $sql);//Read data from result set, return array//$attr = $reslut->fetch_all (); Reads all data, returns the index two-dimensional array//$attr = $reslut->fetch_array (); Reads the data pointed to by the current pointer, returns an array of index associations that exist//$attr = $reslut->fetch_assoc (); Returns an associative array//$attr = $reslut->fetch_row (); Returns an indexed array//$attr = $reslut->fetch_object (); Returns the object/* $arr = Array (), while ($attr = $reslut->fetch_row ()) {Array_push ($arr, $attr);} Var_dump ($arr); * *?></Body></HTML>

Here's another

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?php//Connect Object $db = new mysqli ("localhost", "root", "123", "mydb");//write SQL statement $sql = "INSERT into info values (' p003 ', ' Zhang San ', ' 1 ', ' n001 ', ' 1990-2-3 ');//Execute SQL statement $result = $db->query ($sql);/*if ($result) {echo "executed successfully! ";} else{echo "Execution failed! ";} *///$result->fetch_row ();?></Body></HTML>

PHP Data Access

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.