php insert update delete

Solutions on MaxInterview for php insert update delete by the best coders in the world

showing results for - "php insert update delete"
Gianluca
03 Jul 2017
1//Best practice for performing crud operations in php is to have them in your db
2//create stored procedures for each operation then call them in php 
3//preferably using php pdo
4
5<?php
6$dbname = 'test_db';
7$host = '127.0.0.1';
8$user_name = 'root';
9$user_pass = '';
10
11$con = new PDO("host=$host;dbname=$dbname", $user_name, $user_pass);
12$stmt = $con->prepare('CALL [procedure_name]');
13// if you are performing operations like: insert, update,delete you'll most likely end here
14$stmt->execute();
15// if you are getting data this is an additional step to take when looping through your data
16$result = $stmt->fetch(PDO::FETCH_ASSOC);
17while($res = $result){
18	echo $res['FieldName'];
19}
20
21
22
23
24