Functionmysqli_set_charset | |
FunctionSet the connection with the mysql server, result, verify character set | |
Parameter 1Pass in the resource returned by mysqli_connect | |
Parameter 2Character set type | |
For more notes, please pay attention to the book "13.6 The Ultimate Solution to Garbled Data Display"
Step 5: Prepare the SQL statement
is actually a string of SQL statements.
For example:
<?php
$sql = "insert into user(username,password) values('$username','$password')";
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
We usually assign variables for use in SQL statements. However, there is an error in the variable or SQL statement, which is very difficult to troubleshoot.
We have added this step based on actual work experience.
If an error is reported when executing this step, we can print out the SQL statement and paste it into phpMyAdmin or related tools.
When debugging, if the execution is successful, it means that the problem is not with the SQL statement. If execution fails, double check the SQL statement.
Step 6: Send SQL statement
Type | Description |
---|
Function | mysqli_query |
Function | Send SQL statement |
##Parameter 1 | Pass in the resource returned by mysqli_connect |
Parameter 2 | Pass in the SQL statement sent |
The SQL statement is prepared and needs to be sent to the MySQL server through mysqli_query. The MySQL server will execute the SQL statement sent. Step 7: Determine whether the execution is normal or traverse the dataReadIn step 6, the statement of the select category is sent, and the results usually need to be output and displayed. come out. You need to use the function that traverses the display data. Type | Description |
##Functionmysqli_fetch_array | |
FunctionGet the data in the result set and return the array for convenience | |
Parameter 1Pass Enter the result variable from the query | |
Parameter 2 Pass in MYSQLI_NUM to return the index array, MYSQLI_ASSOC to return the associative array, MYSQLI_BOTH to return the index and association | |
TypeDescription | |
##Function mysqli_fetch_assoc | ##Function |
Get the data in the result set and return the associative array for convenience | Parameter 1 |
Pass in the result variable from the query | |
TypeDescription | |
Functionmysqli_fetch_row | ##Function | Get the data in the result set and return the index array for convenience
| Parameter 1 | The result variable passed in from the query
| |
Type
Description | ##Function |
mysqli_fetch_objectFunction | Get the data in the result result set and return the object for traversal |
Parameter 1 | Pass in the result variable from the query |
Type | Description |
---|
##Function | mysqli_num_rows | Function | Return the total number of results from the query | Parameter 1 | Pass in the result variable from the query |
Type | Description | Function | mysqli_num_rows | Function | Return the total number of query results | Parameter 1 | Pass in the result variable from the query | Note | It is rarely used in actual work, understand | # #Write
In step 6, if the insert statement is sent, you usually need to get whether the execution is successful, or get the auto-incremented ID at the same time. TypeDescription | | ##Functionmysqli_fetch_field | | Function Traverse data rows | | Parameter 1 Pass in the result variable from the query | | Modification and deletion In step 6, if the statements of update and delete categories are sent. Just need to determine whether the execution is successful. We list the data tables of these commonly used functions for everyone to check. Step 8: Close the databaseTypeDescription | | Functionmysqli_close | | Function Close the database connection | | Parameter 1 Pass in the resource returned by mysqli_connect | | The database connection is a resource type. We told you about it when we explained resource types in the previous chapter. All resource types involved are either opened or closed. This ensures that PHP processes and recycles resources more efficiently. Therefore, after the database connection is successful, there is no need to use it. We can close this connection. Others: Display server information functionTypeDescription | | Functionmysqli_get_server_info | | Function Return server information | | Parameter 1 Pass in the resource returned by mysqli_connect | | ##TypeDescription | | Functionmysqli_get_server_version | ##Function | Return server version | Parameter 1 | Pass in the resource returned by mysqli_connect | | Note: mysqli only learns the procedural method. In the actual work of the object-oriented stage, the object usage of mysqli was completely abandoned, and instead the PDO object was used to connect to the database. Next Section<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?> - Chapter1Why choose this course to learn PHP
- Why learn PHP?
- What is PHP
- You can learn even with z...
- Why can't some people lea...
- Chapter2PHP environment installation
- What is the development e...
- Windows environment insta...
- Linux environment install...
- Other development environ...
- Tool selection for writin...
- Chapter3php basic syntax
- PHP basic syntax
- Our first piece of PHP co...
- Variables in php - you wi...
- echo display command
- Learning php annotations
- Data types are not myster...
- PHP integer type is an in...
- PHP data type Boolean (ac...
- PHP data type string
- PHP data type floating po...
- PHP flow control if else ...
- PHP data type NULL type
- php data type array
- Resource type of php data...
- PHP data type viewing and...
- Automatic conversion and ...
- Object (will learn later)
- PHP constants and variabl...
- PHP constants and variabl...
- PHP constants and variabl...
- PHP constants and variabl...
- Variable references for P...
- PHP basic syntax arithmet...
- PHP basic syntax assignme...
- PHP basic syntax: self-in...
- PHP basic syntax comparis...
- Logical operations of php...
- PHP basic syntax bit oper...
- PHP basic syntax: ternary...
- Chapter4PHP process control
- Process control in PHP
- PHP process control if co...
- PHP flow control if state...
- Nested if...else...elseif...
- Multiple nesting of if st...
- Use of branch structure s...
- Use of loop statements in...
- while loop
- The difference between do...
- PHP flow control for loop...
- PHP flow control goto syn...
- Chapter5Basic function syntax of PHP
- Basic function syntax of ...
- PHP function basic syntax...
- PHP custom function callb...
- PHP custom function varia...
- PHP custom function anony...
- Internal function of php ...
- Variable scope of php cus...
- Reference to parameters o...
- PHP custom function recur...
- Static variables of php c...
- php uses system built-in ...
- php file contains functio...
- PHP math commonly used fu...
- PHP function to obtain pe...
- php date validation funct...
- PHP gets localized timest...
- PHP program execution tim...
- PHP string common functio...
- Chapter6PHP arrays and data structures
- PHP arrays and data struc...
- php array definition
- PHP array calculation
- php for loop traverses in...
- php foreach traverses as...
- PHP list, each function t...
- PHP commonly used array m...
- Common functions for php ...
- Chapter7Regular expressions in PHP
- Regular expressions in PH...
- Delimiter expressed by ph...
- Atoms in php regular expr...
- Metacharacters in php reg...
- Pattern modifiers in php ...
- Tips and commonly used re...
- PHP uses regular expressi...
- Chapter8php file system
- File system
- php read file
- php creates and modifies ...
- php creates temporary fil...
- php move, copy and delete...
- php detect file attribute...
- Common functions and cons...
- php file locking mechanis...
- php directory processing ...
- php file permission setti...
- php file path function
- PHP implements file guest...
- PHP implementation exampl...
- Chapter9PHP file upload
- PHP file upload
- When uploading files, you...
- Steps to upload php files
- Precautions for php file ...
- php completes file upload...
- php multiple file upload
- PHP file upload progress ...
- Chapter10PHP image processing
- PHP image processing
- PHP image processing gd2 ...
- PHP uses image processing...
- PHP development verificat...
- php image scaling and cro...
- PHP image watermark proce...
- Chapter11PHP error handling
- Error handling
- PHP error handling prohib...
- PHP error handling error ...
- PHP error handling error ...
- PHP error handling custom...
- Chapter12Getting started with MySQL
- Getting Started with MySQ...
- Mysql database introducti...
- Mysql entertainment expla...
- mysql database installati...
- Data statement operation ...
- Mysql connect to database
- Mysql database operation
- Mysql data table operatio...
- Mysql data field operatio...
- Mysql data type
- Mysql character set
- Mysql table engine
- Mysql index
- Mysql add, delete, modify...
- Mysql add, delete, modify...
- Mysql multi-table joint q...
- Mysql addition, deletion,...
- Mysql add, delete, modify...
- DCL statement
- Learn commonly used Engli...
- Chapter13PHP operates mysql database
- PHP operates mysql databa...
- PHP database connection s...
- PHP operates the database...
- PHP database operation: m...
- PHP database operation: p...
- PHP database operation: b...
- PHP database operation to...
- The ultimate solution to ...
- Chapter14php session management and control
- session overview
- Overview of Cookies for P...
- php session control Cooki...
- PHP session control using...
- php SESSION application e...
- Session management and co...
- Chapter15Making a thief program through cURL
- php curl usage methods an...
- php curl custom get metho...
- php curl uses post to sen...
- Making a thief program th...
- Chapter16Learn commonly used English words in PHP
- List of commonly used Eng...
|