<?php
/**
* Created by Phpstorm.
* User: Great God
* DATE:2017/7/24
* time:11:29
*/
Header (' Content-type:text/html;charset=utf8 ');
Get database connection
$link = Mysqli_init ();
Determine if the Mysqli object was created successfully
if (! $link) {
Exit (' Mysqli object creation failed ');
}
Sets the parameter value of the MYSQLI, which is the setting whether to submit the SQL statement automatically
1 represents the execution of the statement after writing the code, and 0 means that no code execution is performed until close, only in memory
if (!mysqli_options ($link, Mysqli_init_command, ' SET autocommit = 0 ')) {
Exit (' Set auto commit failed ');
}
Failed to set the connection expiration time
if (!mysqli_options ($link, Mysqli_opt_connect_timeout, 5)) {
Exit (' failed to set the connection failure time ');
}
Create MYSQLI Connection database (database attached and database selected)
if (!mysqli_real_connect ($link, ' localhost ', ' root ', ' ', ' pg39 ')) {
Die (' Connection error ' ('. Mysqli_connect_errno (). ‘)‘ . Mysqli_connect_error ());
}
Defines the SQL statement and sends the results back to the database side for execution
Mysqli_set_charset ($link, ' UTF8 ') sets the character set inside the mysqli
if ((!mysqli_set_charset ($link, ' UTF8 '))) {
Exit (' Set database query encoding set failed ... ');
}
Default query parameter Mysqli_use_result (can be written or not written)
$infos = Mysqli_query ($link, "select * from Stu", Mysqli_use_result);
Handling return value Results
$arr = Array ();
if ($infos) {
Mysqli_fetch_array every time a row in the result set is fetched
while ($info = Mysqli_fetch_array ($infos, Mysql_num))//mysql_num Mysql_assoc Mysql_both
{
Array_push ($arr, $info);
}
Processing end gets the data collection to the purge
Mysqli_free_result ($infos);
}
Var_dump ($arr);
Close an open resource
Mysqli_close ($link);
Convert MySQL to Mysqli