Created
August 3, 2020 12:33
-
-
Save literat/e6edcca51ce0dd688223dfc5f00f1358 to your computer and use it in GitHub Desktop.
Article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Article | |
| { | |
| public function __construct() | |
| { | |
| $this->db = new PDO('mysql:host=localhost;port=2020;dbname=LMC', 'editor', '123xyz'); | |
| } | |
| public function save($data) | |
| { | |
| $sql = 'INSERT INTO articles VALUES (' . $_GET['id'] . ', ' . $data['title'] . ', ' . $data['content'] . ')'; | |
| $this->db->query($sql); | |
| } | |
| public function getArticle() | |
| { | |
| $sql = 'SELECT * FROM articles WHERE id = ' . $_GET['id']; | |
| $result = $this->db->query($sql)[0]; | |
| echo '<h1>' . $result['title'] . '</h1>' . '<p>' . $result['content'] . '</p>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment