Common php functions and examples

Source: Internet
Author: User
Common php functions and examples

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );

Mysql_data_seek moves the internal query pointer to the bool mysql_data_seek (resource result_indetifier, int row_number) syntax on the query line. example:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ Res = mysql_query ("SELECT * from product ");
  8. $ Row = mysql_fetch_array ($ res );
  9. For ($ I = 0; $ I <$ num; $ I ++)
  10. $ Row = mysql_fetch_array ($ res );
  11. Mysql_data_seek ($ res, 0); // move the pointer back to the first row of the query result

Mysql_fetch_array: an example of the syntax array mysql_fetch_array (resource result [, int result_type]) that stores the query results in an array (each array element has a record:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ Res = mysql_query ("SELECT * from product ");
  8. $ Row = mysql_fetch_array ($ res );

Mysql_fetch_object retrieves a query result row and stores it as an object. it is used exactly the same as MySQL_fetch_array (). The difference is mysql_fetch_object () only the field name can be used to obtain the query result echo $ row-> fieldname; // use echo $ row-> 0 correctly; // example of the syntax object mysql_fetch_object (resource result:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ Res = mysql_query ("SELECT * from product ");
  8. $ Row = $ mysql_fetch_object ($ res );
  9. While ($ row)
  10. {
  11. Echo $ row à p _ id;
  12. Echo $ row à p _ name;
  13. }

Mysql_insert_id after adding a piece of information using the INSERT command, you can use this function to obtain the newly added record's unique id syntax int mysql_insert_id ([esource link_identifier]) example:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ SQLStr "insert into produce (p_id, p_name) VALUES ('', 'php book ')";
  8. $ Res = mysql_query ($ res );
  9. $ P_id = mysql_insert_id ();

The following is an example of the syntax int mysql_num_rows (resource result) in mysql_num_rows:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ Res = mysql_query ("SELECT * from product ");
  8. $ Num = mysql_num_rows ($ res );

Mysql_query returns an SQL syntax query statement syntax resource mysql_query (string query [, resource link_identifier]) example:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );
  7. $ Res = mysql_query ("SELECT * from product ");

Mysql_select_db select the database name syntax bool mysql_select_db (string database_name [, resource link_identifier]) for access. example:

  1. $ DB_HOST = "localhost ";
  2. $ DB_LOGIN = "root ";
  3. $ DB_PASSWORD = "123456 ";
  4. $ DB_NAME = "flag ";
  5. $ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
  6. Mysql_select_db ($ DB_NAME );

12 3 Next page

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.