<?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