PHP Classes

File: examples/5-update_2.php

Recommend this page to a friend!
  Classes of MarPlo   PDO_MySQLi class   examples/5-update_2.php   Download  
File: examples/5-update_2.php
Role: Example script
Content type: text/plain
Description: Example 5
Class: PDO_MySQLi class
Access MySQL using PDO or MySQLi extensions
Author: By
Last change:
Date: 11 years ago
Size: 823 bytes
 

Contents

Class file image Download
<?php
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class
include('../conn_mysql.php');

// creates object with connection to MySQL
$conn = new PDO_MySQLi($mysql);

// UPDATE with placeholder question marks in the SQL statement,
// and values into an numerical array (in the same order as question marks), numerical index starting from 0
$sql = "UPDATE `testclass` SET `url` = ?, `title` = ? WHERE `id` = ?";
$vals = array('http://marplo.net/', 'Free Courses', 3);

// executes the SQL query, passing the SQL query and the array with values
$resql = $conn->sqlExecute($sql, $vals);

// check if the SQL query succesfully performed, displays the number of affected rows
if($resql) echo 'Updated succesfully '. $conn->affected_rows .' row';
else echo
$conn->error;