Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'config.php';
- abstract class connect {
- protected $link;
- public function __construct($dbhost,$dbuser,$dbpass,$dbname2) {
- $host = $dbhost;
- $user = $dbuser;
- $password = $dbpass;
- $database = $dbname2;
- // $host = 'localhost';
- // $user = 'student';
- // $password = 'c@18504';
- // $database = 'practice';
- $this->link = @mysqli_connect($host, $user, $password, $database);
- if(!mysqli_connect_errno()) {
- } else {
- die("connection error: ". mysqli_connect_error());
- }
- }
- }
- ?>
- class connect {}
- class connect {
- public function sumOrConcate($a, $b){
- return $a + $b;
- }
- }
- $conn = new connect();
- $a = 15;
- $b = 2;
- echo $conn->sumOrConcate($a, $b); //17
- //The variable names do not matter and in fact are not needed.
- //$a and $b are for the scope of the function
- echo $conn->sumOrConcate(8, 5); //13
- class connect {
- public $a, $b;
- public function __construct($a, $b) {
- $this->a = $a;
- $this->b = $b;
- }
- public function sumOrConcate(){
- return $this->a + $this->b;
- }
- }
- $conn = new connect(12, 15);
- echo $conn->sumOrConcate(); //27
- // Since $a and $b are public you can set them
- $conn->a = 2;
- echo $conn->sumOrConcate(); //17
- //If these were private you would need to create getter/setters.
- abstract class connect {
- public function __construc($a, $b) {
- // use $a, $b
- }
- }
- // name of values can be different
- $a = "value1";
- $b = "value2";
- $conn = new connect($a, $b);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement