Learning purpose: Learn to read data
Let’s look at two functions first:
1. mysql_query
Send a query string. Syntax: int mysql_query(string query, int [link_identifier]); Return value: integer
This function sends the query string for MySQL to perform related processing or execution. If the link_identifier parameter is not specified, the program will automatically look for the most recently opened ID. When the query string is UPDATE, INSERT and DELETE, the returned value may be true or false; when the query string is SELECT, a new ID value is returned. When false is returned, it does not mean that the execution is successful but there is no return value, but There is an error in the query string.
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 result into a class variable. If result has no data, a false value is returned.
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, table There is a username field in user, which is similar to
<%
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, we need to connect to the database first. Generally, we require_once('conn.php'); and conn.php contains the code to connect to the database mentioned last time.
A small two commands can complete the work of reading data. Today we will talk about adding, deleting and modifying data next time.