Php--mysqli Expansion Library, delete, change, check

Source: Internet
Author: User

<?php

/**************************mysqli Extension Library ********************************/

/* MySQL database with php mysqli extension, an enhanced version of MySQL extension, improves efficiency, security, and supports object-oriented programming

It also provides a process-oriented programming style

Special description of the ★mysql statement: If the field type of the operation is a string type, it is required to wrap with single quotation marks, and if the field type of the operation is numeric, it can be used in single quotation marks or without ★

*/

/*

Inquire

Object-oriented style 1. Creating a Mysqli Object 2. Manipulating databases 3. Processing results 4. Close Resources

1. Create an Object

$mysqli =new mysqli ("127.0.0.1", "root", "hfcc551", "Test");

Verify that you are connected

if ($mysqli->connect_error)

{

Die ("Connection failed! ". $mysqli->connect_error);

}

2. Operation database (send SQL command)

$sql = "SELECT * from user";

$res = $mysqli->query ($sql);//$res is the result set

3. Processing results

while ($row = $res->fetch_row ())

{

foreach ($row as $k = $v)

{

echo "--". $v;

}

echo "<br/>";

}

4. Close Resources

$res->free ();//Release memory

$mysqli->close ();//close connection

*/


increase, delete, change

$mysqli =new mysqli ("127.0.0.1", "root", "hfcc551", "Test");

if ($mysqli->connect_error)

{

Die ("Connection failed! ". $mysqli->connect_error);

}

$sql = "INSERT into user (Name,password,age) values (' Liu Yi ', MD5 (' sf123456 '), 57)";//Add a record

$sql = "Delete from user where id=17";//delete a record

$sql = "Update user set name= ' small su ' where id=18";//Modify a piece of data

$b = $mysqli->query ($sql);//$b is a Boolean value

if (! $b)

{

echo "Failed! ". $mysqli->error;

}

Else

{

See how many lines of records are affected

if ($mysqli->affected_rows>0)

{

echo "Success!" ";

}

Else

{

echo "No number of rows affected";

}

}

$mysqli->close ();//No resources can be turned off because $b is a Boolean type value so close the connection


Php--mysqli Expansion Library, delete, change, check

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.