Object-oriented eighth day---preprocessing and MySQL transaction

Source: Internet
Author: User


4. Pdostatment objects
4.1 Member methods in Pdostatmen
Fetch
Fetchall
4.2 Set the array type that returns the result
Pdo::fetch_assoc
Pdo::fetch_num
Pdo::fetch_both
Pdo::fetch_objstdclass padding Properties

4.3 PDO processing result set mode
1. Fetch traversal
2, Fetchall All Access
3. Traverse $stmt Object directly

5. Use of PDO pretreatment (emphasis)
5.1 Advantages of preprocessing
Prevent SQL injection
Batch processing can improve SQL processing efficiency

5.2 Pre-processing steps
1. Prepare SQL with placeholders instead of conditional parameters (?). /: Name)
2. Perform preprocessing prepare return Pdostatement object
4. Execute binding parameters
4. Execute SQL
Execute ()
5.3 Preprocessing SQL methods
Prepare
Execute
5.4 How to bind parameters
1. Bindvalue binding value can be a variable
Placeholder? : name:n
2. Bindparam bound value must be a variable * * * *
Placeholder? : name:n
3. Pass in the array directly when execute

5.5 Binding the results of a query
Bindcolumn
The bound variable can be used directly when traversing data

6. PDO transaction mechanism

ACID Properties

6.1 MySQL Transaction
Attention:
① atomicity All operations are either fully executed or completely canceled
After the ② transaction is turned on, all operations are not executed immediately until commit or rollback ends

6.2 MySQL Client operation process
To open a transaction:
Set autocommit = 0; Begin Start transaction;
Write operations, and create restore points
SavePoint PN
End action
Rollback Rollback to PN; Commit
When you roll back to a restore point, the restore points after it are deleted

Using transactions in 6.3 PDO
1. Open the transaction
$pdo->begintransactio ()
2. Perform pretreatment

3. If successful
Commit
4. If the failure
Executing rollback in Catch

Object-oriented eighth day---preprocessing and MySQL transaction

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.