40 lines
764 B
PHP
40 lines
764 B
PHP
<!-- database -->
|
|
|
|
<?php
|
|
class Database
|
|
{
|
|
private static $dbName = 'nodemcu3' ;
|
|
private static $dbHost = 'localhost' ;
|
|
private static $dbUsername = 'root';
|
|
private static $dbUserPassword = '';
|
|
|
|
private static $cont = null;
|
|
|
|
public function __construct() {
|
|
die('Init function is not allowed');
|
|
}
|
|
|
|
public static function connect()
|
|
{
|
|
// One connection through whole application
|
|
if ( null == self::$cont )
|
|
{
|
|
try
|
|
{
|
|
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
|
|
}
|
|
catch(PDOException $e)
|
|
{
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
return self::$cont;
|
|
}
|
|
|
|
public static function disconnect()
|
|
{
|
|
self::$cont = null;
|
|
}
|
|
}
|
|
?>
|