Skip to content

Instantly share code, notes, and snippets.

@literat
Created August 3, 2020 12:33
Show Gist options
  • Select an option

  • Save literat/e6edcca51ce0dd688223dfc5f00f1358 to your computer and use it in GitHub Desktop.

Select an option

Save literat/e6edcca51ce0dd688223dfc5f00f1358 to your computer and use it in GitHub Desktop.
Article
<?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