You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

109 lines
3.2 KiB

<?php
//ini_set('display_errors', 'on');
class Cnotice
{
function __construct()
{
}
function connectionDB()
{
$envFile = __DIR__ . '/../../.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines !== false) {
foreach ($lines as $line) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
putenv("$key=$value");
}
}
}
date_default_timezone_set("Asia/Taipei");
$host = getenv('DB_HOST');
$dbport = getenv('DB_PORT');
$dbuser = getenv('DB_USERNAME');
$dbpassword = getenv('DB_PASSWORD');
$dbname = getenv('DB_DATABASE');
try {
$options = [
PDO::ATTR_PERSISTENT => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
];
$pdo = new PDO('mysql:host=' . $host . ';port=' . $dbport . ';dbname=' . $dbname . '', $dbuser, $dbpassword, $options);
$pdo->exec('SET CHARACTER SET utf8mb4');
return $pdo;
} catch (PDOException $e) {
die("Something wrong: {$e->getMessage()}");
}
}
/**
* 結束資料庫連線
*/
function endConnectionDB($pdo)
{
unset($pdo);
}
/**
* 提交消息 notice
* @param string $kind : 類別 1=系統 2=會議
* @param int $related_id : 關聯序號
* @param string $title : 標題
* @param string $title : 內容
* @param string $permission : 瀏覽權限 員編/ALL=全體
* @param string $creater : 建立者
* @param string $create_at : 建立時間
*/
function sendx($data)
{
$kind = $data['kind'];
$related_id = $data['related_id'];
$title = $data['title'];
$content = $data['content'];
$permission = $data['permission'];
$creater = $data['creater'];
$create_at = $data['create_at'];
$pdo = $this->connectionDB();
$pdo->exec('SET CHARACTER SET utf8mb4');
$str = "
INSERT INTO `notice` (`kind`, `related_id`, `title`, `content`, `permission`, `creater`, `create_at`)
VALUES (?,?,?,?,?,?,?)
";
$sth = $pdo->prepare($str);
$sth->bindValue(1, $kind);
$sth->bindValue(2, $related_id);
$sth->bindValue(3, $title);
$sth->bindValue(4, $content);
$sth->bindValue(5, $permission);
$sth->bindValue(6, $creater);
$sth->bindValue(7, $create_at);
$sth->execute();
$this->endConnectionDB($pdo);
}
}
// $cn = new Cnotice();
// $data = array(
// 'kind' => 1,
// 'related_id' => 1,
// 'title' => "標題",
// 'content' => "內容",
// 'permission' => "M0117",
// 'creater' => "M0117",
// 'create_at' => date("Y-m-d H:i:s")
// );
// $cn->sendx($data);