Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /* DATABASE CONN */
- define('DB_SERVER', '111.111.111.111');
- define('DB_USERNAME', 'user');
- define('DB_PASSWORD', 'passs');
- define('DB_DATABASE', 'db');
- define("BASE_URL", "https://example.com/");
- @error_reporting(E_ERROR | E_WARNING | E_PARSE);
- function connectDB()
- {
- $dbhost=DB_SERVER;
- $dbuser=DB_USERNAME;
- $dbpass=DB_PASSWORD;
- $dbname=DB_DATABASE;
- try {
- $dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
- $dbConnection->exec("set names utf8");
- $dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- return $dbConnection;
- }
- catch (PDOException $e) {
- echo 'DB conn error : ' . $e->getMessage();
- }
- }
- ?>
- <?php
- class userClass
- {
- public function login($Email,$pass)
- {
- try{
- $db = connectDB();
- $hash_sifre= hash('sha256', $pass);
- $stmt = $db->prepare("SELECT `id` FROM `member` WHERE `email`=:Email AND `pass`=:hash_pass");
- $stmt->bindParam("Email", $Email,PDO::PARAM_STR) ;
- $stmt->bindParam("hash_pass", $hash_pass,PDO::PARAM_STR) ;
- $stmt->execute();
- $count=$stmt->rowCount();
- $data=$stmt->fetch(PDO::FETCH_OBJ);
- $db = null;
- if($count)
- {
- $_SESSION['id']=$data->id;
- return true;
- }
- else
- {
- return false;
- }
- }
- catch(PDOException $e) {
- echo '{"error":{"text":'. $e->getMessage() .'}}';
- }
- $db = null;
- }
- public function info($id)
- {
- try{
- $db = connectDB();
- $stmt = $db->prepare("SELECT `name` FROM `member` WHERE `id`=:id");
- $stmt->bindParam("id", $id,PDO::PARAM_INT);
- $stmt->execute();
- $data = $stmt->fetch(PDO::FETCH_OBJ);
- return $data;
- }
- catch(PDOException $e) {
- echo '{"error":{"text":'. $e->getMessage() .'}}';
- }
- }
- }
- ?>
- <?
- include "settings.php";
- include "userClass.php";
- $userClass = new userClass();
- .
- .
- .
- Many another classes here like userClass calling.
- after im using ..
- ?>
- <?
- include "header.php";
- $id = $_SESSION['id'];
- $memberInfo=$userClass->info($id);
- echo $memberInfo->name;
- and like thats many many queries.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement