PHP Operation MySQL Sample memo _php tutorial

Source: Internet
Author: User
Tags sprintf
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 there is an update in the database, then 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 operation needs to manipulate the field $stmt = $this->db->prepare (' SELECT userId, PassWord from the profile WHERE username=? '); $stmt->bind_param ("s", $_username); $rs = $stmt->execute (); $stmt->bind_result ($_userid, $_password); while ($stmt->fetch ()) { Break } $stmt->close (); Query 2, return 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 ()) { $ret = Array ("name" = = $row [0], "points" = = $row [1],); } $result->close (); } true techarticle 1. General Insert $query = INSERT INTO profile ({$userName}), $this-db-query ($query), $userId = sprintf (% userName) D, $this-db-insert_id); $this-db-commit (); 2. In the database as ...

  • 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: 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.