Convert MySQL to Mysqli

Source: Internet
Author: User

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

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.