From e4c9c41a2600e16e0b5197d1911c3660b40b6f78 Mon Sep 17 00:00:00 2001 From: "gary_chen\\gary_chen" Date: Wed, 22 Nov 2023 19:15:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E7=9F=A5=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/class/Cnotice.php | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 wms/class/Cnotice.php diff --git a/wms/class/Cnotice.php b/wms/class/Cnotice.php new file mode 100644 index 00000000..dd9958f6 --- /dev/null +++ b/wms/class/Cnotice.php @@ -0,0 +1,109 @@ + 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);