Example of mysql operations in php

Source: Internet
Author: User
1. general insert $ query = & quot; INSERTINTOProfile (userName) VALUES (& amp; #39 ;{$ userName} & amp; #39;) & quot ;; $ this-& gt; db-& gt; query ($ query); $ userId = sprintf (& qu 1. general insert $ query = "insert into Profile (userName) VALUES ('{$ userName}')"; $ this-> db-> query ($ query ); $ userId = sprintf ("% d", $ this-> db-> insert_id); $ this-> db-> commit (); 2. if any, update the database. If no, INSERT $ query = "insert into BookRead (userId, bookId, count) VALUES ($ _ UserId, $ _ bookId, 1) on duplicate key update count = count + 1 "; $ this-> db-> query ($ query ); $ this-> db-> commit (); 3. UPDATE $ query = "UPDATE Profile Set deviceToken = '{$ _ token}' WHERE userId = $ _ userId"; $ this-> db-> query ($ query ); $ this-> db-> commit (); 4. query 1: the field to be operated $ stmt = $ this-> db-> prepare ('select userId, passWord FROM Profile WHERE userName =? '); $ Stmt-> bind_param ("s", $ _ userName); $ rs = $ stmt-> execute (); $ stmt-> bind_result ($ _ userId, $ _ passWord); while ($ stmt-> fetch () {break;} $ stmt-> close (); query 2, returns the query result array $ query = "SELECT name, points FROM Profile WHERE 1 order by points desc limit $ _ from, $ _ "; if ($ result = $ this-> db-> query ($ query) {while ($ row = $ result-> fetch_row ()) {$ ret = array ("name" => $ row [0], "points" => $ row [1],) ;}$ result-> close ();}
Related Article

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.