php - Trying to convert from mysqli to pdo -


try { $pdo = new pdo("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword); } catch (pdoexception $e){ exit('datebase error.'); } // db login info defined, didnt post here  $username = $_get["user"]; $password = $_get["passwd"]; //$data = mysqli_query($mysqli, "select * users username='".$username."'"); //$hash = mysqli_fetch_object($data); $query = "select username, password, loginreqkey, banned users username='$username'";  //if (password_verify('rasmuslerdorf', $hash)) { if ($stmt = $pdo->prepare($query)) { $stmt->execute(array($username, $password, $loginreqkey, $banned)); //$stmt->bind_result($username, $password, $loginreqkey, $gbanned); //  $result = $stmt->fetch(pdo::fetch_lazy); //$dt = $stmt->fetchall()   ;  //$query->execute(array($username, $password)); if (password_verify($password, $result['password'])) {  while($r = $stmt->fetchall(pdo::fetch_assoc)){  echo "{";  echo '"state": "success",';     echo '"loginreqkey": "' . $r['loginreqkey'] . '",';      echo '"banstatus": "' . $r['banned'] . '"';     echo "}"; }  /* close statement */ $stmt = null; } else { die("fake pw lol"); }  /* close connection */ $pdo = null; } //} 

trying convert code mysqli pdo , having issues.. trying information in query , verify user password echo rest of information, (for unreal project) tried couple of solutions on php documentation , stackoverflow sending information mysql server.

$username = $_get["user"]; $password = $_get["passwd"];  $pdo = new pdo("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbusername, $dbpassword, array(   pdo::attr_errmode=>pdo::errmode_exception // ....since there no further error handling in script ));  $stmt = $pdo->prepare("select username, password, loginreqkey, banned users username=:username"); $stmt->bindparam(':username', $username); $stmt->execute(); $result = $stmt->fetch(pdo::fetch_assoc); if ($result && password_verify($password, $result['password'])) {     echo json_encode [         "state" => "success",         "loginreqkey" => $result['loginreqkey'],         "banstatus" => $result['banned'],     ]; } 

that's how go it.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -