Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. //Database connection that is working
  2. class Database {
  3. private $_connection;
  4. private static $_instance; //The single instance
  5. private $_host = "localhost";
  6. private $_username = "root";
  7. private $_password = "testuser";
  8. private $_database = "testpassword";
  9. /*
  10. Get an instance of the Database
  11. @return Instance
  12. */
  13. public static function getInstance() {
  14. if(!self::$_instance) { // If no instance then make one
  15. self::$_instance = new self();
  16. }
  17. return self::$_instance;
  18. }
  19. // Constructor
  20. private function __construct() {
  21. $this->_connection = new mysqli($this->_host, $this->_username,
  22. $this->_password, $this->_database);
  23.  
  24. // Error handling
  25. if(mysqli_connect_error()) {
  26. trigger_error("Failed to conencto to MySQL: " . mysqli_connect_error(),
  27. E_USER_ERROR);
  28. }
  29. }
  30. public function result()
  31. {
  32. echo $this->query;
  33.  
  34. }
  35. // Magic method clone is empty to prevent duplication of connection
  36. private function __clone() { }
  37. // Get mysqli connection
  38. public function getConnection() {
  39. return $this->_connection;
  40. }
  41. }
  42. //select statement that is not working as a class
  43. class getText
  44. {
  45. private static $_instance;
  46. private $field;
  47. private $result;
  48. public static function getInstance() {
  49. if(!self::$_instance) {
  50. self::$_instance = new self();
  51. }
  52. return self::$_instance;
  53. }
  54. public function __construct()
  55. {
  56. $db = Database::getInstance();
  57. $mysqli = $db->getConnection();
  58. $sql = "SELECT * FROM template_text_boxes WHERE idtemplate_text_boxes='61'";
  59. $this->result = mysqli_query($mysqli, $sql);
  60. if ($this>result) {
  61. while ($row = mysqli_fetch_assoc($this->result)) {
  62. $this->field[] = array('text1' => $row['text1'], 'text2' => $row['text2'], 'text3' => $row['text3'], 'text4' => $row['text4'], 'text5' => $row['text5'], 'text6' => $row['text6'], 'text7' => $row['text7'], 'text8' => $row['text8'], 'text9' => $row['text9'], 'text10' => $row['text10'], 'text11' => $row['text11'], 'text12' => $row['text12'], 'text13' => $row['text13'], 'text14' => $row['text14'], 'text15' => $row['text15'], 'text16' => $row['text16'], 'text17' => $row['text17'], 'text18' => $row['text18'], 'text19' => $row['text19'], 'text20' => $row['text20'], 'text21' => $row['text21'], 'text22' => $row['text22'], 'text23' => $row['text23'], 'text24' => $row['text24'], 'text25' => $row['text25'], 'text26' => $row['text26'], 'text27' => $row['text27'], 'text28' => $row['text28'], 'text29' => $row['text29'], 'text30' => $row['text30'], 'text31' => $row['text31'], 'text32' => $row['text32'], 'text33' => $row['text33'], 'text34' => $row['text34'], 'text35' => $row['text35'], 'text36' => $row['text36'], 'text37' => $row['text37'], 'text38' => $row['text38'], 'text39' => $row['text39'], 'text40' => $row['text40'], 'text41' => $row['text41'], 'text42' => $row['text42'], 'text43' => $row['text43'], 'text44' => $row['text44'], 'text45' => $row['text45'], 'text46' => $row['text46'], 'text47' => $row['text47'], 'text48' => $row['text48'], 'text49' => $row['text49'], 'text50' => $row['text50'], 'text57' => $row['text57'], 'text58' => $row['text58']);
  63. }
  64. }
  65. }
  66. public static function get_text($this->field, $x)
  67. {
  68. echo ->field[0][$x];
  69. }
  70.  
  71. public static function text($field, $x)
  72. {
  73. return -> field[0][$x];
  74. }
  75. }
  76. //how I want to access each database column
  77. $getText ->text($field,'text49');
  78. $getText = new getText();
  79. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement