update and deleting a record php code code example

Example: php insert update delete

//Best practice for performing crud operations in php is to have them in your db
//create stored procedures for each operation then call them in php 
//preferably using php pdo

<?php
$dbname = 'test_db';
$host = '127.0.0.1';
$user_name = 'root';
$user_pass = '';

$con = new PDO("host=$host;dbname=$dbname", $user_name, $user_pass);
$stmt = $con->prepare('CALL [procedure_name]');
// if you are performing operations like: insert, update,delete you'll most likely end here
$stmt->execute();
// if you are getting data this is an additional step to take when looping through your data
$result = $stmt->fetch(PDO::FETCH_ASSOC);
while($res = $result){
	echo $res['FieldName'];
}

Tags:

Php Example