Update rows wrapper based on PDO

Updates table rows based on specified filters and data.

php
fork add to bundle source
function mysql_update_table($table, $where, $data) { $handle = new PDO('mysql:host=127.0.0.1;dbname=db', 'user', 'pwd'); foreach ( $data as $key => $value ) { $values[] = "`{$key}` = :{$key}"; $bind[':' . $key] = $value; } foreach ( $where as $key => $value ) { $filters[] = "`{$key}` = :{$key}"; $bind[':' . $key] = $value; } $sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $values) . ' WHERE ' . implode(' AND ', $filters); $st = $handle->prepare($sql); $st->execute($bind); return $st; }

usage

load_function('mysql_update_table'); mysql_update_table('users', ['id' => 7], ['last_login' => time()]); // will update "last_login" column for row with id = 7 in users table
← how to use this in app?
create log ...inout