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 Se T 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 () {<span style = "white-space: pre"> </span> break ;} $ stmt-> close (); query 2, returns the query result array $ query = "SELECT name, points FROM Profile WHERE 1 order by points desc limit $ _ from, $ _ to "; if ($ result = $ this-> db-> query ($ query) {while ($ row = $ result-> fetch_row ()) {<span style = "white-space: pre"> </span> $ ret = array ("name" => $ row [0], "points" => $ row [1],) ;}$ result-> close ();}