Good morning,
im trying to do something simple which is updating a few mysql rows using function and giving file path as WHERE parameter.
That's my update function which is in class that extends PDO.
public function update($table, $data, $where, $whereBindArray = array()) {
ksort($data);
$fieldDetails = NULL;
foreach($data as $key=> $value) {
$fieldDetails .= "`$key`=:$key,";
}
$fieldDetails = rtrim($fieldDetails, ',');
$sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where");
foreach ($data as $key => $value) {
$sth->bindValue(":$key", $value);
}
foreach ($whereBindArray as $key => $value) {
$sth->bindValue(":$key", $value);
}
$sth->execute();
}
There's my php code:
$rpath = realpath(dirname(__FILE__)) . '/' . basename( __FILE__ );
$db->update(
'as_texts', array(
"content" => $_POST['content'],
"lastupdate" => date("Y-m-d H:i:s"),
"rpath = :r",
array( "r" => $rpath )
));
and there goes my table sql
CREATE TABLE `as_texts` (
`ID` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`rpath` VARCHAR(200) NOT NULL,
`content` TEXT NOT NULL,
`lastupdate` DATETIME NOT NULL default '0000-00-00 00-00-00',
PRIMARY KEY (`ID`),
UNIQUE KEY (`rpath`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
So it's all about editing content, lastupdate field when WHERE is rpath which is file path.