Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "INSERT INTO MyGuests (firstname, lastname, email)
- VALUES ('John', 'Doe', 'john@example.com')";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "New record created successfully";
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- class Car
- {
- // declaring properties
- public $wheel_number,$color;
- // name setter method
- public function set_name($integer,$color)
- {
- // assign the $string to the object’s property name
- $this->wheel_number=$integer;
- $this->color=$color;
- }
- // name getter method
- public function get_name()
- {
- // return the object’s name property
- return $this->wheel_number;
- $this->color;
- }
- }
- $john = new Car; // creating object of class Person
- $john->set_name("4","red"); // setting the name property
- echo "The wheel number of our car ".$john->wheel_number; // getting name property
- echo "The color of our car is ".$john->color; // getting name property
- ?>
Add Comment
Please, Sign In to add comment