Facing the object database

Source: Internet
Author: User

<?php

Object-oriented way to access the database

Created object $db = new mysqli ("localhost", "root", "123", "MyDB");

Determine if the connection is faulted/*if (Mysqli_connect_error ()) {echo ' Connection failed!  "; Exit }*/

!mysqli_connect_error () or Die ("Connection failed! ");

Write SQL statement $sql = "INSERT into Info values (' p010 ', ' Zhang San ', true, ' n002 ', ' 1988-2-3 ')";

Executes the SQL statement, the query statement returns the result set object, the other statements return TRUE or false $result = $db->query ($sql);

Reads data from the result set object//$attr = $result->fetch_all (mysqli_both); Returns all data in the form of a two-dimensional array//$attr = $result->fetch_array (); Returns the data that the current pointer points to//$attr = $result->fetch_assoc (); Returns the data that the current pointer points to (associative array)//$attr = $result->fetch_object (); Return object//$attr = $result->fetch_row (); Returns an indexed array of//var_dump ($ATTR); /* while ($attr = $result->fetch_row ()) {var_dump ($attr);} */

Var_dump ($result);

?>

Facing the object database

Related Article

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.