Objective: to learn to read data
Let's first look at two functions:
1. mysql_query
Returns a query string. Syntax: int mysql_query (string query, int [link_identifier]); Return Value: integer
This function sends a query string for MySQL to perform related processing or execution. If the link_identifier parameter is not specifiedProgramThe latest opened ID is automatically searched. If the query string is Update, insert, or delete, the return value may be true or false. If the query string is select, a new ID value is returned. If the return value is false, the query string is incorrect, instead of running successfully but without returning values.
2. mysql_fetch_object returns class data. Syntax: Object mysql_fetch_object (INT result, int [result_typ]); Return Value: Class
This function is used to split the query result into class variables. If the result contains no data, false is returned.
Let's look at a simple example:
<?
$ Exec = "select * from user ";
$ Result = mysql_query ($ Exec );
While ($ rs = mysql_fetch_object ($ result ))
{
Echo "username:". $ RS-> username. "<br> ";
}
?>
Of course, the table user has a username field, which is similar
<%
Exec = "select * from user"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open exec, Conn, 1, 1
Do while not Rs. EOF
Response. Write "username:" & RS ("username") & "<br>"
Rs. movenext
Loop
%>
Of course, you need to connect to the database first. Generally, we require_once ('conn. php'), and in conn. php, we talked about connecting to the databaseCode.
Two small commands can be used to read data. Today we will talk about how to add, delete, and modify data.