Last active
May 9, 2020 10:12
-
-
Save XxAnonimeKxX/f892f0fd24af74a4b65fdb7a48e11c69 to your computer and use it in GitHub Desktop.
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 DB{ | |
| private $_pdo; | |
| private $count = 0; | |
| public function __construct(){ | |
| try{ | |
| $this->_pdo = new PDO('mysql:host=localhost;dbname=wakamegroup', 'root' , ''); | |
| //echo 'good'; | |
| } | |
| catch (PDOException $e){ | |
| } | |
| } | |
| public function insert($table, $data){ | |
| $sql = "INSERT INTO " . $table . " (" . implode(",",array_keys($data)) . ') VALUES (' . "'" . implode("','",array_values($data)) . "')"; | |
| $stmt = $this->_pdo->prepare($sql); | |
| $stmt->execute(); | |
| } | |
| public function getName($name, $table, $field, $operator, $str){ | |
| $sql = "SELECT " . $name . " FROM " . $table . " WHERE " . $field . $operator . $str; | |
| $stmt = $this->_pdo->query($sql); | |
| return $stmt->fetchAll(); | |
| } | |
| } | |
| ?> |
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 | |
| require_once 'classes/db.php'; | |
| $getProd = new DB; | |
| echo $getProd->getName('name', 'products', 'id', '>', '0'); | |
| //zwraca mi SELECT name FROM products WHERE id>0 | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment