Object-oriented way to access the database

Source: Internet
Author: User
Object-oriented way to access database build object to determine whether the connection is error (two ways) write SQL statement Execute SQL statement read data loop output from result set Object $db = new mysqli ("localhost", "root", "" "," Z-stu ");//Method one if (Mysqli_connect_error ())    {echo "connection error"; Exit;} Method two!mysqli_connect_error () or Die ("Connection failed! $sql = "SELECT * from info"; $result = $db->query ($sql);//Method one while ($atr = $result->fetch_row ()) {}//method two $atr = $res Ult->fetch_all (); foreach ($atr as $v) {echo $v [0];} Reads data from the result set object $attr = $result->fetch_all (mysqli_both); Returns all data as a two-dimensional array $attr = $result->fetch_array (); Returns the data that the current pointer points to, whether the default index can be an index or an association, or a combination of $attr = $result->fetch_assoc (); Returns the data (associative array) pointed to by the current pointer $attr = $result->fetch_object (); Return object $attr = $result->fetch_row (); Returns an indexed array

Object-oriented way to access the database

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.