Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class databaseConnect {
- public function __construct($serverName, $dbName, $dbUsername, $dbPassword) {
- $this->serverName = $serverName;
- $this->dbName = $dbName;
- $this->dbUsername = $dbUsername;
- $this->dbPassword = $dbPassword;
- }
- public function databaseQuery() {
- $conn = new PDO("mysql:host={$this->serverName};dbname={$this->dbName}", $this->dbUsername, $this->dbPassword);
- $query = $conn->query("Select * from posts");
- foreach ($query as $row) {
- echo $row['id'] . ".<br>";
- echo $row['subject'] . ".<br>";
- echo $row['content'] . "<br>";
- echo $row['date'] . ".<br>";
- }
- }
- }
- $classname = new databaseConnect("Localhost", "phplessons", "root", "");
- $classname->databaseQuery();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement