Guest User

Untitled

a guest
Jun 1st, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "username";
  4. $password = "password";
  5. $dbname = "";
  6.  
  7. try {
  8.     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9.     // set the PDO error mode to exception
  10.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.     $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  12.    VALUES ('John', 'Doe', 'john@example.com')";
  13.     // use exec() because no results are returned
  14.     $conn->exec($sql);
  15.     echo "New record created successfully";
  16.     }
  17. catch(PDOException $e)
  18.     {
  19.     echo $sql . "<br>" . $e->getMessage();
  20.     }
  21.  
  22. $conn = null;
  23.  
  24.  
  25.  
  26. class Car
  27. {
  28.      // declaring properties
  29.      public $wheel_number,$color;
  30.      // name setter method
  31.      public function set_name($integer,$color)
  32.      {
  33.            // assign the $string to the object’s property name
  34.            $this->wheel_number=$integer;
  35.            $this->color=$color;
  36.      }
  37.      // name getter method
  38.      public function get_name()
  39.      {
  40.            // return the object’s name property
  41.            return $this->wheel_number;
  42.                   $this->color;
  43.  
  44.      }
  45. }
  46. $john = new Car; // creating object of class Person
  47. $john->set_name("4","red"); // setting the name property
  48. echo "The wheel number of our car ".$john->wheel_number; // getting name property
  49. echo "The color of our car is ".$john->color; // getting name property
  50.  
  51. ?>
Add Comment
Please, Sign In to add comment