Code has been added to clipboard!

PHP MySQL Update for PDO Users

Example
<?php
  $server = 'host';
  $user = 'user';  
  $pass = 'pass';
  $db = 'db';
  try {
    $conn = new PDO("mysql:host=$server;dbname=$db",$user, $pass); 
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $sql = "UPDATE users SET uesrname='john.doe' WHERE user_id=2";  	
    // Prepare statement
    $stmt = $conn->prepare($sql);
    // execute the query   
    $stmt->execute();
    // echo a message to say the  
    UPDATE succeeded
    echo $stmt->rowCount() . "Update successful";
  } catch (PDOException $e) {
    echo $sql . "</br>" . $e->getMessage();
  }
  $conn = null;  
?>