Salve ragazzi,
ho fatto questa classe per la connessione:
connection.php
solo che io vorrei fare una funzione nella classe per evitare di scrivermi ogni volta tutto quel try-catch-if per connettere ad esempio:
install.php
Come potrei fare?
ho fatto questa classe per la connessione:
connection.php
PHP:
<?php
#classe per la connessione al DB.
include "notorm-master/NotORM.php";
class connection
{
static $dsn = 'mysql:dbname=xxx;host=xxx';
static $user = 'xxx';
static $pass = 'xxx';
static $host = 'xxx';
static $dbname = 'xxx';
static $table = 'xxx';
}
try
{
$pdo = new PDO(connection::$dsn, connection::$user, connection::$pass);
}
catch (PDOException $error)
{
echo 'Connection failed: ' . $error->getMessage();
}
if (isset($pdo))
{
$dbn = new NotORM($pdo);
}
?>
install.php
PHP:
<?php
require_once('connection.php');
try
{
$pdo = new PDO(connection::$dsn, connection::$user, connection::$pass);
}
catch (PDOException $error)
{
echo 'Connection failed: ' . $error->getMessage();
}
if (isset($pdo))
{
$dbn = new NotORM($pdo);
}
?>
Come potrei fare?