Jump to content

mysql pdo not throwing exceptions while connecting except "object(PDO)#1 (0) { }"

Recommended Posts

hi guys i recently deployed an app in heroku through ubuntu. After troubleshooting it multiple times i finally got to install and retrieve data in clearDB mysql server in heroku with mysql workbench. But the problem is after deploying the php code, i get the following message

 object(PDO)#1 (0) { }

when i var_dump the PDO connection, here is the code to the dbconfig file that has the connection details.

      $server = $url["host"];
      $username = $url["user"];
      $password = $url["pass"];
      $db = substr($url["path"],1);
      $host= "mysql:host=$server;dbname=$db";
    try {
        $conn=new PDO($host , $username, $password);
    } catch (PDOException $exc) {
        echo $exc->getMessage();
    echo "<br>";
    include 'classes.inc.php';
     echo "<br>".$db."<br>";
    $project= new projecteg($conn);

please help me with this error as i'm running like nowhere with this problem.

Link to post
Share on other sites

since the script was not pulling data i finally used exit to check connection and it was giving that to pdo, normally it should atleast give the statement when we use var_dump right but it was not showing the connection credentials either here is the login script so far while troubleshooting.

include_once 'dbconfig.inc.php';
if (isset($_POST['submit-login'])) {
$uname= htmlspecialchars($_POST['unamel']);
$unamel=  stripslashes($_POST['unamel']);
$pass= htmlspecialchars($_POST['passl']);
$pass1= stripslashes($_POST['passl']);
$passl=  md5($pass1);
$user = $project->viewProtectedArea($unamel,$passl);var_dump($user);
if ($user!="") {
                  if (isset($_SESSION[u2])) {
                      header("location: ../home.php?u={$_SESSION['u2']}&v={$_SESSION['uname']}");
                  } else {
                       header("location: ../home.php?u={$_SESSION['uname']}");
if (isset($_SESSION['app'])&&$_SESSION['uname']!="") {
    //echo 'your name is '.$_SESSION['fname'];  
    header("location: ../home.php?u={$_SESSION['uname']}");
                  } else {
                      header("location: ../index.php?usernotfound?id=017");
Edited by shan2batman
Link to post
Share on other sites

plus the class is here

public function viewProtectedArea($unamel,$passl)
                 // $active=1;
                   $stmth= $this->_db->prepare("select * from user where uname=:uname and pass=:pass and activated=1");
                  return $stmth->fetchAll(PDO::FETCH_ASSOC);
Link to post
Share on other sites

if you are not getting any output from var_dump($user), then either if (isset($_POST['submit-login'])) { is false and none of the code is running, or one of the pdo statements is throwing an error/exception, which php will catch for you, based on the posted code, and use it's error_reporting/display_errors/log_errors settings to determine what happens with the actual error information. 


what exactly are your error_reporting/display_errors/log_errors settings? if they are not set to either report and display all errors or report and log all errors, nothing will happen with the error information and since you have already output something to the browser, there won't be a http 500 error either. error_reporting should always be set to E_ALL (or a -1) and you should have display_errors set to ON when developing and debugging code, and display_errors set to OFF and log_errors set to ON when running code on a live/public server.


next, this code won't work as written, you are using ->fetchAll() to retrieve the data, so you will either be getting an empty array if the query didn't match a row, or an array of row(s) if it did. You would either need to reference the zero'th element of the array to get the row of data, or you would need to just use ->fetch(), since the query should at most match a single row.


you should also not use md5() for the password hash. see php's password_hash() and password_verify() functions.


htmlspecialchars() is an output function. it is used when you output data in a html context. it is not used on data being supplied as input to an sql query. you are also not actually using the two variables that are being set in the lines using htmlspecialchars().


the problem that required the use of stripslashes() on data was removed from php several years ago. there's currently no need to apply stripslashes() to data.

Edited by mac_gyver
Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.