Guest User

Untitled

a guest
Jul 12th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. define( 'DATA_BASE', 'db_name' );
  2. define( 'USER_NAME', 'user_name' );
  3. define( 'PASSWORD' , 'password' );
  4. define( 'HOST' , 'localhost' );
  5.  
  6. class MysqliDB
  7. {
  8. private $user;
  9. private $password;
  10. private $database;
  11. private $host;
  12.  
  13. public function __construct( $user, $password, $database, $host = 'localhost' )
  14. {
  15. $this->user = $user;
  16. $this->password = $password;
  17. $this->database = $database;
  18. $this->host = $host;
  19. }
  20.  
  21. public function __construct()
  22. {
  23. $this->user = USER_NAME;
  24. $this->password = PASSWORD;
  25. $this->database = DATA_BASE;
  26. $this->host = HOST;
  27. }
  28. }
  29.  
  30. class MysqliDB {
  31.  
  32. public function __construct( $user = USER_NAME, $password = PASSWORD, $database = DATA_BASE, $host = HOST ) {}
  33. }
  34.  
  35. new MysqliDB( null, 1234 );
  36.  
  37. public function __construct( $user = USER_NAME, $password = PASSWORD, $database = DATA_BASE, $host = HOST )
  38. {
  39. $this->user = $user;
  40. $this->password = $password;
  41. $this->database = $database;
  42. $this->host = $host;
  43.  
  44. $this -> checkIntegrity();
  45. }
  46.  
  47. public function checkIntegrity()
  48. {
  49. if( empty( $this -> username ) ) {
  50. die( 'Usuário MySQL ausente' );
  51. }
  52. }
  53. }
  54.  
  55. class MysqliDB {
  56.  
  57. public function __construct()
  58. {
  59. list( $user, $password, $database, $host ) = func_get_args();
  60.  
  61. $this->user = $user;
  62. $this->password = $password;
  63. $this->database = $database;
  64. $this->host = $host;
  65. }
  66. }
  67.  
  68. list( $user, $password, $database, $host ) = func_get_args() + array( USER_NAME, PASSWORD, DATA_BASE, HOST );
  69.  
  70. class Foo {
  71.  
  72. function Foo() {
  73.  
  74. // No PHP4 esse método era o construtor
  75. }
  76. }
  77.  
  78. class Foo {
  79.  
  80. function Foo() {
  81.  
  82. echo __METHOD__, '<br />';
  83. }
  84.  
  85. public function __construct() {
  86.  
  87. echo __METHOD__, '<br />';
  88. }
  89. }
Add Comment
Please, Sign In to add comment