Skip to content
Snippets Groups Projects
Commit 2370d377 authored by Sudhir's avatar Sudhir
Browse files

added database class ,making the server connection through static func.......

added database class ,making the server connection through static func.... (learn about static function inside a class ==>static runs without  object initialization:      , in processs of updating to class(oops) from structural programing +>started with load.php->create connection
parent 80047f79
No related branches found
No related tags found
No related merge requests found
<?php
class Database
{
public static $conn = null;
public static function getConnection()
{
if (Database::$conn = null){
$servername = "mysql.selfmade.ninja";
$username = "sudhir";
$password = "sudhirsys@12";
$dbname = "sudhir_newdb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); //TODO :replace this with exception handling:
}else{
Database::$conn =$conn;
return Database::$conn;
}
}
else{
return Database::$conn;
}
}
}
\ No newline at end of file
......@@ -8,6 +8,12 @@ class Mic{
public $usb_port;
public $light;
public static function testFunction(){
printf("this is a static function , this can run without an object construction/initialization");
}
public function __construct($brand){
printf("CONSTRUCTING OBJECT.......");
$this->brand = ucwords($brand);
......@@ -28,5 +34,11 @@ class Mic{
public function setmodel($model){ //to keepor convert upercase values:
$this->model = ucwords($model); //UC WORD IN INBUILT FUNC
}
public function __destruct()
{
printf(" destructing object... brand: $this->brand <br> ");
}
}
\ No newline at end of file
<?php
class user
{
}
\ No newline at end of file
<?php
include_once 'includes/mic.class.php';
include_once 'includes/Database.class.php';
function load_template($name){
include __DIR__."/../_templates/$name.php";
......@@ -13,19 +15,7 @@
}
}
function signup($user,$pass,$email,$phone_number){
$servername = "mysql.selfmade.ninja";
$username = "sudhir";
$password = "sudhirsys@12";
$dbname = "sudhir_newdb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
}
$conn = Database::getconnection();
$sql= "INSERT INTO `auth` (`username`, `password`, `email`, `phone`, `blocked`, `activate`)
VALUES ('$user', '$pass', '$email', '$phone_number', '0', '1');";
......
......@@ -31,17 +31,18 @@ $mic3 = new Mic('hyper');
$mic1->model ="RODA";
$mic2->model ="REDGEAR";
$mic3->model ="saas";
// $mic3->model ="saas";
$mic1->setlight("white");
printf($mic1->light);
echo "\n";
$mic3->setmodel("hyper castr");
$mic3->setmodel("mic3genz");
print("THE MODEL OF THE 3rd MIC IS ".$mic3->getModelProxy());
echo "\n";
print("\n".$mic2->getbrand()); //present in function construct:
print("\n".$mic1->getbrand());
print("\n".$mic1->getModelProxy());
print("\n".$mic3->getModelProxy());
?>
</pre>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment