Connect Database query Basics

Source: Internet
Author: User

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP//1. Making Connection Objects$db=NewMysqli ("localhost", "User name", "Password", "Database to operate");//2. Determine if the link is wrongif(Mysqli_connect_error()){     die("Connection Failed");}//3. Preparing SQL statements$sql= "SELECT name from info where code= ' p001 '";//4. Execute SQL statement, return result set object$result=$db->query ($sql);//5. Take data from the result set//$attr = $result->fetch_all ();//Returns a two-dimensional array with all parameters//three optional parameters: Mysqli_assoc Returns an associative array, Mysqli_num returns an indexed array , Mysqli_both returns both index and association, and does not need double quotation mark//fetch_attry (); Returns the current data, returns a one-dimensional array, the default is the index association has//FETCH_ASSOC (); Returns the current data,  Returns an associative array of one dimension//fetch_object (); Returns the object of the current data//fetch_row (); Returns the current data, returning an indexed array/*$attr = $result->fetch_all (), foreach ($attr as $v) {echo "<div>{$v [0]}--{$v [1]}</div>";}*//*While ($attr = $result->fetch_row ()) {echo "<div>{$attr [0]}--{$attr [1]}--{$attr [2]}--{$attr [3]}--{$    Attr[4]}</div> "; }*/$attr=$result-Fetch_all ();//Var_dump ($attr);//echo $attr [0][0]?></body>

Connect Database query Basics

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.