PHP Data Access

Source: Internet
Author: User

<?php//job: Find out the info table to display//1 in a table. Create a Connection object $db = new mysqli ("localhost", "root", "", "mydb");//(server name, user name, password, table name)//2. Determine if the connection is faulted!mysqli_connect_error () or Die ("Connection Failed"),/*if (Mysqli_connect_error ()) {echo "Connection failed"; exit ();//Exit program}*///3. Write mysql data $sql = "SELECT * from Info";//4. Execute SQL statement, query statement, if execution succeeds return result set object, if execution fails return false$result = $db->query ($sql);//5. Reads an object from the result set/*if ($result) {var_dump ($result->fetch_row ());//Returns an array of rows of data (indexed array) while ($row = $result->fetch_row ()) { Var_dump ($row);} Var_dump ($result->fetch_assoc ());//Returns a row of data (associative array) var_dump ($result->fetch_all ());//Returns all data (two-dimensional array) Var_dump ($ Result->fetch_object ());//returns one row of data (object)}*/$attr = $result->fetch_all (); echo "<table cellpadding= ' 0 ' cellspacing= ' 0 ' width= ' 100% ' border= ' 1 ' > "; foreach ($attr as $v) {echo" <tr><td>{$v [0]}</td><t     d>{$v [1]}</td><td>{$v [2]}</td><td>{$v [3]}</td></tr> "; };echo "</table>", echo "<select><option value= ' 1 ' >{$attr [1][1]}</option><option value= ' 1 ' >{$attr [1][1]}</option><option value= ' 1 ' >{$attr [2][1]}</option><option value= ' 1 ' >{$attr [3][1]}</option></select> ";/*echo" <select> "echo" <option value= ' 1 ' >{$attr [1 ][1]}</option><option value= ' 1 ' >{$attr [1][1]}</option><option value= ' 1 ' >{$attr [2][1]} </option><option value= ' 1 ' >{$attr [3][1]}</option> "; echo" </select> ";*/?>

  

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.