By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

change from PDO to MSQLI

P: 14
how do i change this to mysqli?


Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     require 'connect.php';
  3.  
  4.     session_start();
  5.  
  6.     $username = "";
  7.     $password = "";
  8.  
  9.     if(isset($_POST['username'])){
  10.         $username = $_POST['username'];
  11.     }
  12.     if (isset($_POST['password'])) {
  13.         $password = $_POST['password'];
  14.  
  15.     }
  16.  
  17.     echo $username ." : ".$password;
  18.  
  19.     $q = 'SELECT * FROM users WHERE username=:username AND password=:password';
  20.  
  21.     $query = $dbh->prepare($q);
  22.  
  23.     $query->execute(array(':username' => $username, ':password' => $password));
  24.  
  25.  
  26.     if($query->rowCount() == 0){
  27.         header('Location: ind.php?err=1');
  28.     }else{
  29.  
  30.         $row = $query->fetch(PDO::FETCH_ASSOC);
  31.  
  32.         session_regenerate_id();
  33.         $_SESSION['sess_user_id'] = $row['id'];
  34.         $_SESSION['sess_username'] = $row['username'];
  35.         $_SESSION['sess_userrole'] = $row['role'];
  36.  
  37.         echo $_SESSION['sess_userrole'];
  38.         session_write_close();
  39.  
  40.         if( $_SESSION['sess_userrole'] == "admin"){
  41.             header('Location: adminhome.php');
  42.         }else{
  43.             header('Location: userhome.php');
  44.         }
  45.  
  46.  
  47.     }
  48.  
  49.  
  50. ?>
Sep 11 '15 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,031
Why do you want to do that? (see: this)

I think PDO has more advantages than MySQLi
Sep 12 '15 #2

P: 14
it is because most of my pages are in MYSQLI except the login. changing all the pages to PDO might take longer
Sep 22 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.