phreak3r Posted May 10, 2019 Share Posted May 10, 2019 I chose this category as I thought my topic would best fit here. I am running 14.2 Slackware Linux with the latest version of PHP. In the error log, I receive the error: Uncaught PDOException: could not find driver in 'x file path'. I am positive that I have the required extensions and modules installed and enabled. Here is my code for the user.php class where I take the user information and add it to the database: <?php require('dbcon/dbcon.php'); class User { public $avatar; public $bio; public $video_count; public $c_status; public $username; public $password; public $email; public $doc; public $last_logged_in; //if ($_SERVER['REQUEST_METHOD'] == 'POST') { public function addUser(PDO $pdo) { // add user info to db $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; $doc = date("Y-m-d h:i:s"); // account date last seen/logged in // add account age $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio, doc) VALUES (:username, :password, :email, :cstat, :bio, :doc)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email_address); $query->bindValue(':doc', $doc); $query->bindValue(':bio', $bio); $query->bindValue(':cstat', $c_status); $query->execute(); // create variables // initialize variables // bind values of variables being entered into database } // addUser($pdo); //} // isLoggedIn - checks if user is logged in or not // getUser - returns/gets user??? // avatar // bio // registration date // video count // last logged in // username // email address } ?> Here is my code for the dbcon.php class where the database connection is made: <?php $host = "localhost"; $database = "soapbox"; $username = "drb"; $password = "m1n3craft"; // Create connection try { $pdo = new PDO('mysql:host=localhost;dbname=soapbox;', $username, $password); } catch (PDOExcpetion $e) { print "Error!: " . $e.getMessage() . "<br/>"; die(); } /* Print error message and or code to the screen if there is an error. */ ?> and the code for the confirmation.php class where the data is displayed temporarily: <?php include('header.php'); include('user.php'); require('dbcon/dbcon.php'); //include('functions.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $user = new User(); $user->addUser(); // if username exists do not continue... } ?> <!DOCTYPE html> <html> <head> <title>soapbox - confirmation</title> </head> <br> <?php $username = $_POST['username']; $email = $_POST['email']; $format = "The data provided has been sent to the server and is being inserted into the database. In order to complete the process, %s, we need you to confirm your account. If not confirmed, your account will be deleted a month from the marked registration date. We have sent you an email at %s, the provided email upon registration. Thank you and cheers! - The Staff at Soapbox"; echo sprintf($format, $username, $email); session_destroy(); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/308685-uncaught-pdoexception-could-not-find-driver/ Share on other sites More sharing options...
kicken Posted May 10, 2019 Share Posted May 10, 2019 Create a page with the code <?php phpinfo(); and check it's output for a PDO section. It should show a line saying: Quote PDO drivers mysql If it doesn't, then you haven't loaded the proper extensions. Quote Link to comment https://forums.phpfreaks.com/topic/308685-uncaught-pdoexception-could-not-find-driver/#findComment-1566559 Share on other sites More sharing options...
phreak3r Posted May 10, 2019 Author Share Posted May 10, 2019 kicken, sqlite and odbc only show up for the enabled drivers. Well, I can take back my earlier claim of being sure that the extensions were enabled. I do have them installed to my knowledge when taking a look at /etc/php.ini, I see among the many extensions: mysql.so, mysqli.so, pdo.so, pdo_mysql.so, pdo_sqlite.so and pdo_odbc.so Quote Link to comment https://forums.phpfreaks.com/topic/308685-uncaught-pdoexception-could-not-find-driver/#findComment-1566560 Share on other sites More sharing options...
kicken Posted May 10, 2019 Share Posted May 10, 2019 Sometimes there are separate ini files for cli, cgi, and apache modules. The phpinfo() output will also tell you which php.ini file it's looking at so you know which one to edit. Look for a line similar to Quote Loaded Configuration File /etc/php/7.2/fpm/php.ini Quote Link to comment https://forums.phpfreaks.com/topic/308685-uncaught-pdoexception-could-not-find-driver/#findComment-1566561 Share on other sites More sharing options...
phreak3r Posted May 10, 2019 Author Share Posted May 10, 2019 Yeah, it is loading the /etc/php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/308685-uncaught-pdoexception-could-not-find-driver/#findComment-1566566 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.