Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- class Mysql {
- private $conn;
- function __construct() {
- $this->conn = new PDO('mysql:host=***;dbname=***;charset=UTF-8','***','***') or
- die('There was a problem connecting to the database.');
- }
- function verify_Username_and_Pass($un, $pwd) {
- $query = "SELECT Username
- FROM Conference
- WHERE Username = :un AND Password = :pwd";
- $stmt = $this->conn->prepare($query);
- $stmt->bindParam(':un', $un);
- $stmt->bindParam(':pwd', $pwd);
- $stmt->execute();
- if ($stmt->rowCount() > 0) {
- // User exist
- $stmt->bindColumn('First Name', $firstName);
- $_SESSION["FirstName"] = $firstName;
- die($_SESSION["FirstName"]);
- return true;
- $stmt->close();
- }
- else {
- // User doesn't exist
- //die("failure");
- return false;
- $stmt->close();
- }
- }
- }
- ?>
- class Mysql
- {
- private $conn;
- public $error;
- public $username;
- function __construct()
- {
- try {
- $this->conn = new PDO( 'mysql:host=localhost;dbname=****', 'root', '****' );
- $this->conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
- }
- catch ( Exception $e ) {
- $this->error = $e->getMessage();
- }
- }
- function verify_Username_and_Pass( $un, $pwd )
- {
- $query = "SELECT Username
- FROM Conference
- WHERE Username = :un AND Password = :pwd";
- $stmt = $this->conn->prepare( $query );
- if( !$stmt ) {
- $this->error = $this->conn->errorInfo();
- return false;
- }
- $stmt->bindParam( ':un', $un );
- $stmt->bindParam( ':pwd', $pwd );
- $stmt->execute();
- if ( $stmt->rowCount() > 0 ) {
- // User exist
- $this->username = $stmt->fetchColumn();
- return true;
- }
- else {
- // User doesn't exist
- return false;
- }
- }
- }
- session_start();
- $db = new Mysql();
- if( !$db->error ) {
- if( $db->verify_Username_and_Pass ( 'user', 'test' )) {
- $_SESSION["FirstName"] = $db->username;
- }
- else
- echo 'Unknown user';
- }
- var_dump( $db );
- Unknown user
- object(Mysql)#1 (3) {
- ["conn":"Mysql":private]=> object(PDO)#2 (0) { }
- ["error"]=> array(3)
- { [0]=> string(5) "42S02"
- [1]=> int(1146)
- [2]=> string(39) "Table 'xxxx.Conference' doesn't exist" }
- ["username"]=> NULL }
Add Comment
Please, Sign In to add comment