westdc-zf1/application/module/Westdc/Visual/Record.php

48 lines
1.0 KiB
PHP

<?php
namespace Westdc\Visual;
class Record
{
public $db;
function __construct($recordType)
{
$this->initDatabase();
}
public function initDatabase()
{
$config = \Zend_Registry::get('config');
$dsn = "pgsql:host={$config->visual_db->hostname};"
."port={$config->visual_db->port};"
."dbname={$config->visual_db->database};"
."user={$config->visual_db->username};"
."password={$config->visual_db->password}";
$this->db = new \PDO($dsn);
}
public function makeSql($table,$index,$fieldValue,$fieldTime)
{
$sql = "SELECT
\"$index\" as \"index\", \"$fieldValue\" as \"value\", \"$fieldTime\" as \"time\"
FROM \"$table\"
ORDER BY
extract(year from \"$fieldTime\") ASC,
extract(month from \"$fieldTime\") ASC,
extract(day from \"$fieldTime\") ASC,
";
$rs = $this->db->query($sql);
return $rs;
}
public function utcMsTime($time=''){
if(empty($time))
return (time()+8*3600)*1000;
else
return $time*1000;
}
}