PHP ADODB Update with place holder

From CoderLearner
Jump to: navigation, search

PHP ADODB Update Multiple Records

Use question mark place holder and update records.

Syntax ADODB UPDATE Record


$sql = "UPDATE user_infor SET email=? WHERE id=?";
$conn1->Execute($sql, array('email',2));

Example 1

<?php

include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);

$sql = "UPDATE user_infor SET email=? WHERE id=?";

$my_data = array(
	 array('pm11@aa.com',1),
	 array('jg11@aa.com',2),
	 array('mlex11@aa.com',3),
	 array('km11@aa.com',4)
);

for ($i = 0; $i < count($my_data); $i++) {
	$d = $conn1->Execute($sql, $my_data[$i]);
	if (!$d) {
		print 'error' . $conn1->ErrorMsg() . '<br>';
	}
	else {
		echo 'Success! Update';
		echo "<br/>";
	}
}

?>