10 days to learn the fifth day of PHP

Source: Internet
Author: User
Tags execution query return
Learning Purpose: Learn to read data

Look at two functions first:
1, mysql_query
Send out a query string. Syntax: int mysql_query (string query, int [link_identifier]); return value: Integer

This function sends out the query string for MySQL to do related processing or execution. If you do not specify the Link_identifier parameter, the program automatically looks for the most recently opened ID. If the query string is UPDATE, INSERT, and DELETE, the return may be true or false, and the query's string is a SELECT that returns a new ID value, and when false, it is not a successful execution but no return value, but a string of queries that is wrong Miss.

2, Mysql_fetch_object return class data. Syntax: Object mysql_fetch_object (int result, int [Result_typ]); Return value: Class

This function is used to split query result results into class variables. Returns the value of False if result has no data.

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, there is a username field in table user, which is similar to the one in ASP
<%
Exec= "SELECT * from User"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
Do as not rs.eof
Response.Write "Username:" &rs ("username") & "<br>"
Rs.movenext
Loop
%>
Of course, we have to connect the database first, generally we require_once (' conn.php '), and conn.php inside is the last time the code that connects the database.

The small two commands can complete the work of reading the data, said here today the next time to say that the data added delete changes.




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.