Skip to content

Commit ef4ed99

Browse files
committed
Add coursera assignment files
1 parent 75b723b commit ef4ed99

File tree

16 files changed

+830
-0
lines changed

16 files changed

+830
-0
lines changed

4_Advanced/OOPs/1_basic.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
class Car{
3+
public $make;
4+
public $model;
5+
public $year;
6+
7+
8+
public function __construct($make, $model, $year){
9+
$this->make = $make;
10+
$this->model = $model;
11+
$this->year = $year;
12+
}
13+
14+
public function getCarDetails(){
15+
return "Make: $this->make, Model: $this->model, Year: $this->year<br>";
16+
}
17+
}
18+
19+
$car1 = new Car("Toyota", "Corolla", 2015);
20+
echo $car1->getCarDetails();

4_Advanced/OOPs/2_vehicle.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
class Vehicle{
4+
public $type;
5+
public $brand;
6+
7+
public function __construct($type, $brand){
8+
$this->type = $type;
9+
$this->brand = $brand;
10+
}
11+
12+
function get_type(){
13+
return $this->type;
14+
}
15+
16+
function get_brand(){
17+
return $this->brand;
18+
}
19+
}
20+
21+
$vehicle1 = new Vehicle("Car", "Toyota");
22+
echo "Type: ".$vehicle1->get_type().", Brand: ".$vehicle1->get_brand()."<br>";
23+
$vehicle2 = new Vehicle("Bike", "Honda");
24+
echo "Type: ".$vehicle2->get_type().", Brand: ".$vehicle2->get_brand()."<br>";

4_Advanced/OOPs/3_interface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
Interface MyInterface{
3+
public function getName();
4+
public function getAge();
5+
}
6+
7+
class MyClass implements MyInterface{
8+
public function getName(){
9+
echo "My name A<br>";
10+
}
11+
public function getAge(){
12+
echo "My age 20<br>";
13+
}
14+
}
15+
16+
$obj = new MyClass();
17+
$obj->getName();
18+
$obj->getAge();

5_MySQL/1_connection.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
$servername = "localhost";
3+
$username = "root";
4+
$password = "";
5+
$databasename = "practice1";
6+
// using MYSQLi Object-oriented way
7+
$conn = new mysqli($servername, $username, $password, $databasename);
8+
9+
// using MYSQLi Procedural way
10+
// $conn = mysqli_connect($servername, $username, $password, $databasename);
11+
12+
if ($conn->connect_error) {
13+
die("Connection failed: " . $conn->connect_error);
14+
}
15+
echo "Connected successfully";
16+
17+
$sql = "CREATE TABLE `practice1` . `viaphp` (
18+
`id` INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
19+
`address` VARCHAR(30) NOT NULL,
20+
`marks` INT(6) NOT NULL )";
21+
22+
if ($conn->query($sql) === TRUE) {
23+
echo "Table created successfully";
24+
} else {
25+
echo "Error creating table: " . $conn->error;
26+
}

5_MySQL/2_createDb.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
//Procedural oriented way
3+
$link = mysqli_connect("localhost", "root", "");
4+
5+
if ($link === false) {
6+
die("ERROR: Could not connect. " . mysqli_connect_error());
7+
}
8+
9+
$sql = "CREATE DATABASE practice2";
10+
if (mysqli_query($link, $sql)) {
11+
echo "Database created successfully";
12+
} else {
13+
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
14+
}
15+
16+
mysqli_close($link);
17+
18+
//Object oriented way
19+
/* $servername = "localhost";
20+
$username = "root";
21+
$password = "";
22+
$databasename = "practice2";
23+
// using MYSQLi Object-oriented way
24+
$conn = new mysqli($servername, $username, $password);
25+
26+
if ($conn->connect_error) {
27+
die("Connection failed: " . $conn->connect_error);
28+
}
29+
echo "Connected successfully";
30+
31+
$sql = "CREATE DATABASE practice2";
32+
if ($conn->query($sql) === TRUE) {
33+
echo "Database created successfully";
34+
} else {
35+
echo "Database exists";
36+
}
37+
38+
$conn->close(); */

0 commit comments

Comments
 (0)