Build a connection, create a Connection object
$db = new Mysqli ("localhost", "root", "123", "MyDB");
Judging if there is an error
/*if (mysqli_connect_error ())
{
echo "Connection failed! ";
Exit
}*/
Mysqli_connect_error () Die ("Connection Failed"): "";
Write SQL statements
$sql = "SELECT * from Info";
Executes the SQL statement, returning the result set object
$reslut = $db->query ($sql);
reading data from the result set, returning an array
$attr = $reslut->fetch_all (); Reads all data, returns an indexed two-dimensional array
$attr = $reslut->fetch_array (); Reads the data that the current pointer points to, and returns an array that exists for the Index association
$attr = $reslut->fetch_assoc (); Returns an associative array
$attr = $reslut->fetch_row (); Returns an indexed array
$attr = $reslut->fetch_object (); Return object
/* $arr = array ();
while ($attr = $reslut->fetch_row ())
{
Array_push ($arr, $attr);
}
Var_dump ($arr); * *
Connecting objects
$db = new Mysqli ("localhost", "root", "123", "MyDB");
Write SQL statements
$sql = "INSERT into info values (' p003 ', ' Zhang San ', ' 1 ', ' n001 ', ' 1990-2-3 ')";
Execute SQL statement
$result = $db->query ($sql);
/*if ($result)
{
echo "executed successfully! ";
}
Else
{
echo "Failed to execute!" ";
}*/
$result->fetch_row ();
Beware of MySQL injection attacks
PHP data access (for example, MySQL database)