<?php
/**
 * Create Connection To Database And If has error add
 * error text and number in session then redirect to serverError.php page
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    16-08-2020
 * @edited_by
 * @last_edit_date
 * @todo           Nothing
 */
if(isset($_SESSION['errorArray']))
    unset($_SESSION['errorArray']);
if(empty($hostSms) || empty($userConnection) || empty($passwordConnection) || empty($dataBase) || !isset($chain) || $chain != "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad") {
    $_SESSION['errorArray'] = array('String' => $errorEmpty, 'No' => -1, 'MySql' => '');
    header("location: serverError.php");
    exit;
}
@$conn = mysqli_connect($hostSms, $userConnection, $passwordConnection, $dataBase);
if(mysqli_connect_errno()) {
    $_SESSION['errorArray'] = array('String' => "errorConn", 'No' => mysqli_connect_errno(), 'MySql' => mysqli_connect_error());
    header("location: serverError.php");
    exit;
} else {
    if(!empty(mysqli_connect_errno($conn)) || !empty(mysqli_connect_error($conn))) {
        $_SESSION['errorArray'] = array('String' => "errorDb", 'No' => mysqli_errno($conn), 'MySql' => mysqli_error($conn));
        header("location: serverError.php");
        exit;
    }
}
mysqli_set_charset($conn, "latin1");
return $conn;
?>
