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