Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2. require_once 'config.php';
  3.  
  4. abstract class connect {
  5. protected $link;
  6. public function __construct($dbhost,$dbuser,$dbpass,$dbname2) {
  7.  
  8. $host = $dbhost;
  9. $user = $dbuser;
  10. $password = $dbpass;
  11. $database = $dbname2;
  12. // $host = 'localhost';
  13. // $user = 'student';
  14. // $password = 'c@18504';
  15. // $database = 'practice';
  16. $this->link = @mysqli_connect($host, $user, $password, $database);
  17. if(!mysqli_connect_errno()) {
  18.  
  19. } else {
  20. die("connection error: ". mysqli_connect_error());
  21.  
  22. }
  23. }
  24. }
  25. ?>
  26.  
  27. class connect {}
  28.  
  29. class connect {
  30. public function sumOrConcate($a, $b){
  31. return $a + $b;
  32. }
  33. }
  34.  
  35. $conn = new connect();
  36. $a = 15;
  37. $b = 2;
  38. echo $conn->sumOrConcate($a, $b); //17
  39.  
  40. //The variable names do not matter and in fact are not needed.
  41. //$a and $b are for the scope of the function
  42. echo $conn->sumOrConcate(8, 5); //13
  43.  
  44. class connect {
  45. public $a, $b;
  46. public function __construct($a, $b) {
  47. $this->a = $a;
  48. $this->b = $b;
  49. }
  50. public function sumOrConcate(){
  51. return $this->a + $this->b;
  52. }
  53. }
  54.  
  55. $conn = new connect(12, 15);
  56. echo $conn->sumOrConcate(); //27
  57. // Since $a and $b are public you can set them
  58. $conn->a = 2;
  59. echo $conn->sumOrConcate(); //17
  60. //If these were private you would need to create getter/setters.
  61.  
  62. abstract class connect {
  63. public function __construc($a, $b) {
  64. // use $a, $b
  65. }
  66. }
  67.  
  68. // name of values can be different
  69. $a = "value1";
  70. $b = "value2";
  71.  
  72. $conn = new connect($a, $b);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement