How to resolve PDO ERROR in SQLSTATE[HY000] [1524] Plugin is not loaded
max-jacob
-
max-jacob -
max-jacob -
Hello,
I usually program with Wamp but since I migrated to Easy PHP
with the following details:
Apache 2.4.25 x86 - PHP 5.6.30 x86 Port: 80
MySQL 5.7.17 x86 Port: 3306
Now when I launch my application, I do get the login page but when I try to log in with a correct login, I get the error message:
PDO ERROR in SQLSTATE[HY000] [1524] Plugin '*4F57BFFF7B9480A7D39BBEB8618276A816FD1BFA' is not loaded
Honestly, I don't know what to do. I am on Win10 64 Bits.
However, my connection uses PDO but I still use Mysqli in my code; I don't know if that's the problem. Even if that's the case, Wampserver handled it well.
Thank you in advance for your help.
I usually program with Wamp but since I migrated to Easy PHP
with the following details:
Apache 2.4.25 x86 - PHP 5.6.30 x86 Port: 80
MySQL 5.7.17 x86 Port: 3306
Now when I launch my application, I do get the login page but when I try to log in with a correct login, I get the error message:
PDO ERROR in SQLSTATE[HY000] [1524] Plugin '*4F57BFFF7B9480A7D39BBEB8618276A816FD1BFA' is not loaded
Honestly, I don't know what to do. I am on Win10 64 Bits.
However, my connection uses PDO but I still use Mysqli in my code; I don't know if that's the problem. Even if that's the case, Wampserver handled it well.
Thank you in advance for your help.
5 answers
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
Bonjour, peut-être pourrais-tu nous montrer ton code, sans oublier d'utiliser ceci: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code -
Hello
my connection uses PDO but I'm still using Mysqli
What??
If you are using Mysqli... Your connection must be in mysqli!!
--
Best regards,
Jordane -
Bonjour et merci de votre aide @Jordan 45 et yg_be,
I mixed Mysqli code with PDO code in my app that was working well locally, but it's on the production server that I faced all the problems in the world. Sometimes it works well, sometimes there are unexplained bugs.
Your comments are welcome
The source code of my login page is:
<?php
ob_start();
session_start();
//session_destroy();
if(!empty($_POST)){
$maVariable = $_POST;
$_SESSION['agentNomUtilisateur'] = $_POST['agentNomUtilisateur'];
//Database connection
require_once('inc/db.php');
$usernameVerification = "SELECT * FROM agent WHERE agentNomUtilisateur = '".$maVariable['agentNomUtilisateur']."' ";
$requete = mysqli_query($mysqli, $usernameVerification);
if (mysqli_num_rows($requete) >=1){
while($row = mysqli_fetch_assoc($requete)){
//Decrypting passwords from the database
if(password_verify($maVariable['agentMotDePasse'], $row['agentMotDePasse'])){
if($row['agentStatus'] == 0){
session_destroy();
die("<br><br><br><br><br>
<center><img class='mb-4' src='img/logo.png'>
<br><br><br>
<h2>Sorry!<br>Your account has been disabled by the administration.<br>
If you think this is a mistake, please contact an administrator.</h2>
<a href='index.php'>Back to login page</center></a>");
}
$_SESSION['utilisateur'] = '';
$_SESSION['roleuser']= $row['roleId'];
header('Location:app/index.php');
}else{
$error_login = "Incorrect password";
}
}
} else {
$error_login = "Incorrect username";
}
mysqli_close($mysqli);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="noindex,nofollow" />
<link rel="icon" href="img/favicon.png">
<title>My App</title>
<meta http-equiv="refresh" content="600;URL=http://mywebapp.com">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/signin.css" rel="stylesheet">
</head>
<body class="text-center">
<form class="form-signin" action="" method="post" name="connect_form">
<img class="mb-4" src="img/logo.png" alt="" >
<?php
if (isset($error_login)){
echo "<p style='color:red'>$error_login</p>";
} ?>
<label for="inputEmail" class="sr-only">User</label>
<input type="text" id="agentNomUtilisateur" class="form-control" placeholder="Username" name="agentNomUtilisateur" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="agentMotDePasse" class="form-control" placeholder="Password" name="agentMotDePasse" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
<p class="mt-5 mb-3 text-muted">© 2017-2020 Central African Post</p>
</form>
</body>
</html>
Below is now the code for the private page that is accessed after a successful login
Any comments are welcome.
<?php
ob_start();
session_start();
if(!isset($_SESSION['agentNomUtilisateur']))
{
header("location:../disconnected.php"); // redirect
exit; // stop the script
}
//The session is open, we can display the page
require_once('../inc/db.php');//Database connection
//Query to display the username
$agentNomUtilisateur = $_SESSION['agentNomUtilisateur'];
$ps = $pdo -> prepare("SELECT * FROM agent WHERE agentNomUtilisateur = ?");
$params=array($agentNomUtilisateur);
$ps -> execute($params);
$agent=$ps->fetch();
//Redirect to admin MENU
if($agent['agentNiveauAcces']==1){
header("location:../app/admin.php"); // redirect
exit; // stop the script
}
?>
<!doctype html>
<html lang="fr">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="noindex,nofollow" />
<link rel="icon" href="../img/favicon.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.css">
<link rel="stylesheet" href="../css/custom.css">
<title>My App</title>
<?php header("refresh:600;url=../app/d.php"); ?>
</head>
<body>
<?php
//Importing the menu
require_once('../inc/menu.php');
?>
-
<?php
//Connection to the database via PDO
try{
$strConnection = 'mysql:host=localhost;dbname=MonDatabaseName';
$pdo = new PDO ($strConnection, 'MonDatabaseUsername', 'MonDatabasePassword');
// Enable PDO errors
// $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// default fetch mode: FETCH_ASSOC / FETCH_OBJ / FETCH_BOTH
// $bdd->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
}
catch (PDOException $e){
$msg = 'PDO ERROR in ' . $e->getMessage();
die ($msg);
}
?>
There you go, it's typically the code.-
The problem is, as I was telling you, not to mix PDO and Mysqli.
In your first script, you are using mysqli... while you are loading the file db.php which connects using PDO.
You should first check if the PDO module is present (and enabled) on your server.
To do this, you can create a PHP file at the root of your site (named for example checkPdo.php)
inside it<?php if ( extension_loaded('pdo') ) { echo " PDO is there! "; echo " You can replace your mysqli code with PDO"; } else { echo " No PDO... use only mysqli "; }
Then you run it.
-
-
Result: PDO is here! You can replace your mysqli codes with PDO.
OK, I will try to replace mysqli with PDO.