[PHP]idiorm #8 save
$record = ORM::for_table($this->table_name)->where('id', $id)->find_one(); if(empty($record)){ return false; } foreach ($data as $key => $value){ $record->set($key,$value); } $result = $record->save();
$record = ORM::for_table($this->table_name)->where('id', $id)->find_one(); if(empty($record)){ return false; } foreach ($data as $key => $value){ $record->set($key,$value); } $result = $record->save();
define('DB_ENCRYPT_KEY','aabbccddeeff'); require_once __DIR__ . '/idiorm.php'; ORM::configure('mysql:host=localhost;dbname=xxxx'); ORM::configure('username', 'yyy'); ORM::configure('password', 'zzz'); ORM::configure('driver_options', [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ]); $query = "INSERT INTO {$table_name}(`e_id`,`description`) VALUES(:e_id,AES_ENCRYPT(:description,'xxyyzz'))"; result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']); $query = "UPDATE {$table_name} SET `description`=AES_ENCRYPT(:description,'xxyyzz') WHERE `e_id` = :e_id"; result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']);
define('DB_ENCRYPT_KEY','aabbccddeeff'); require_once __DIR__ . '/idiorm.php'; ORM::configure('mysql:host=localhost;dbname=xxxx'); ORM::configure('username', 'yyy'); ORM::configure('password', 'zzz'); ORM::configure('driver_options', [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ]); $email = "xxxx@gmail.com"; ORM::configure('logging', true); try{ $orm = ORM::for_table('users')->select("id")->select_expr("AES_DECRYPT(`email`,'".DB_ENCRYPT_KEY."')","email")->select_expr("AES_DECRYPT(`name`,'".DB_ENCRYPT_KEY."')","name"); $orm->where_raw("AES_DECRYPT(`email`,?) = ?",array(DB_ENCRYPT_KEY,$email)); $record = $orm->find_one(); }catch (PDOException $e){ return null; } echo "<pre>"; var_dump(ORM::get_last_query()); echo "</pre>"; if(!empty($record)) { echo "<pre>"; echo $record->id; echo $record->email; echo $record->name; echo "</pre>"; }
public function get_std_by_array($arr,$include_keys = null) { $tmp = new stdClass(); foreach ($arr as $key => $v){ if(empty($include_keys) || (!empty($include_keys) && in_array($key,$include_keys))) $tmp->$key = $v; } return $tmp; } public function get_datas { $sql = array(); $sql[] = "SELECT * FROM wp_posts"; $this->init_pgsql(); try{ $res = ORM::raw_execute(implode(" ",$sql)); $statement = ORM::get_last_statement(); $rows = array(); $results = array(); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $results[] = $this->get_std_by_array($row); } }catch (PDOException $e){ } return empty($results) ? null : $results; }
try{ $sql = "SELECT * FROM shops WHERE name LIKE ? OR name LIKE ?"; $words = array("%銀座%","%御徒町%"); $items = ORM::for_table('shops')->raw_query($sql,$words)->find_array(); }catch (PDOException $e){ return null; } return $items;
$this->init_pgsql(); try{ $orm = ORM::for_table('users')->select_expr("DISTINCT CONCAT(team,'_',job)","tj")->select('team')->select('job'); $orm->where_in('team',$teams); $records = $orm->find_array(); }catch (PDOException $e){ return null; } return $records;
public function init_pgsql()
{
if($this->_init_pgsql)return;
$this->_init_pgsql = true;
ORM::configure(‘pgsql:host=’.PDB_HOST.’;port=’.PDB_PORT.’;dbname=’.PDB_DB.’;’);
ORM::configure(‘username’, PDB_ID);
ORM::configure(‘password’, PDB_PW);
}
public function get_data_by_id($id)
{
$this->init_pgsql();
try{
$orm = ORM::for_table(‘wp_posts’)->join(‘wp_postmeta’, array(‘wp_posts.ID’, ‘=’, ‘wp_postmeta.post_id’))->select(‘*’)->where_equal(‘wp_posts.ID’,$id)->limit(1);
$data = $orm->find_array();
}catch (PDOException $e){
return null;
}
return empty($data) ? null : $data;
}
require_once 'idiorm.php'; ORM::configure('mysql:host=localhost;dbname=dev_db'); ORM::configure('username', 'root'); ORM::configure('password', ''); ORM::configure('driver_options', [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, ]); function echo_json($data) { header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); } $words = mb_split('[\s, ]',addcslashes(trim($_POST['keywords']),'\_%')); try{ $orm = ORM::for_table('entries')->select('id')->where_equal('deleted','0')->order_by_asc('id'); foreach ($words as $w) { $w = trim($w); if($w !== '') $orm->where_like('search', "%{$w}%"); } $recipes = $orm->find_many(); }catch (PDOException $e){ } $result_data = array(); if(!empty($recipes)){ foreach ($recipes as $recipe) $result_data[] = $recipe->html_id; } echo_json($result_data); exit;