Last active
October 30, 2015 20:18
-
-
Save FreeFly19/fde6177e17680db702e2 to your computer and use it in GitHub Desktop.
This file contains 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 "UserManager.php"; | |
$userManager = new UserManager(); | |
$userManager->insert("Sasha", "superPassword"); | |
var_dump($userManager->selectAll()); |
This file contains 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 UserManager | |
{ | |
/** | |
*@var \PDO | |
*/ | |
private $pdo; | |
public function __construct(){ | |
$this->pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password'); | |
} | |
public function insert($name, $password){ | |
$statement = $this->pdo->prepare("INSERT INTO `users` (`id`, `name`, `password`) VALUES (null, :name, :password)"); | |
$statement->bindValue("name", $name); | |
$statement->bindValue("password", $password); | |
$statement->execute(); | |
} | |
public function selectAll(){ | |
$statement = $this->pdo->query("SELECT * FROM users"); | |
return $statement->fetchAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment