Created
January 12, 2016 10:43
-
-
Save VictorFursa/2d8b7f3c5e1abe994b59 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 $server = 'localhost'; | |
| private $userName = 'root'; | |
| private $passwrod = ''; | |
| private $select = 'catalog'; | |
| private $charset = "utf8"; | |
| private $sql = ""; | |
| function __construct(){ | |
| $this->sql(); | |
| $this->query($this->sql); | |
| } | |
| function connect(){ | |
| return mysql_connect($this->server, $this->userName,$this->passwrod); | |
| } | |
| function select_db(){ | |
| return mysql_select_db($this->select); | |
| } | |
| function charset(){ | |
| return mysql_set_charset($this->charset); | |
| } | |
| function query($sql){ | |
| return mysql_query($sql); | |
| } | |
| function format($result){ | |
| $a=1; | |
| $array = array(); | |
| while ($categories = mysql_fetch_array($result)) { | |
| $array[] = $categories; | |
| } | |
| foreach($array as $key =>$value){ | |
| echo "<b>№" . $a++ . | |
| "<b> Имя </b>: " . $value['firstName'] ."<br>" . | |
| "<b> <em> Текст: </em></b>" . $value['message'] . "<hr>"; | |
| } | |
| } | |
| function sql(){ | |
| $this->connect(); | |
| $this->select_db(); | |
| $this->charset(); | |
| } | |
| } | |
| $db = new Db(); | |
| $db->format($db->query("SELECT * FROM guest_book")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment