The fifth day of learning php in ten days. Objective: to read data first, read two functions: 1. output a query string using mysql_query. Syntax: intmysql_query (stringquery, int [link_identifier]); return value: integer learning 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 specified, the program automatically searches for the recently opened ID. 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 ."
";
}
?>
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 ")&"
"
Rs. movenext
Loop
%>
Of course, you need to connect to the database first. generally, we require_once ('Conn. php'), while conn. php contains the code used to connect to the database.
Two small commands can be used to read data. today we will talk about how to add, delete, and modify data.
First, let's look at two functions: 1. mysql_query sends a query string. Syntax: int mysql_query (string query, int [link_identifier]); return value: integer...