shan2batman Posted October 8, 2017 Share Posted October 8, 2017 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. $url=parse_url(getenv("CLEARDB_DATABASE_URL")); $server = $url["host"]; $username = $url["user"]; $password = $url["pass"]; $db = substr($url["path"],1); $host= "mysql:host=$server;dbname=$db"; var_dump($host); try { $conn=new PDO($host , $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $exc) { echo $exc->getMessage(); } var_dump($conn); echo "<br>"; var_dump($exc); 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. Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/ Share on other sites More sharing options...
requinix Posted October 8, 2017 Share Posted October 8, 2017 That's not an error. In fact it means the connection worked. What's your actual problem? You don't want that output? Then remove all those var_dump()s. 1 Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552525 Share on other sites More sharing options...
shan2batman Posted October 8, 2017 Author Share Posted October 8, 2017 actually requinix i'm sorry the real problem statement is that i'm not able to retrieve values from db which has values in it through a login script because of that the app is not able to log in users. Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552526 Share on other sites More sharing options...
shan2batman Posted October 8, 2017 Author Share Posted October 8, 2017 (edited) 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. <?php 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); exit(); if ($user!="") { $_SESSION['id']=$user['user_id']; $_SESSION['fname']=$user['fname']; $_SESSION['lname']=$user['lname']; $_SESSION['uname']=$user['uname']; $_SESSION['email']=$user['email']; $_SESSION['phone']=$user['phone']; $_SESSION['avatar']=$user['avatar']; $_SESSION['app']=TRUE; $user_ok=TRUE; 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 October 8, 2017 by shan2batman Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552527 Share on other sites More sharing options...
requinix Posted October 8, 2017 Share Posted October 8, 2017 If the problem is logging users in then you need to post that code. Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552528 Share on other sites More sharing options...
shan2batman Posted October 9, 2017 Author Share Posted October 9, 2017 the login script is above Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552546 Share on other sites More sharing options...
shan2batman Posted October 9, 2017 Author Share Posted October 9, 2017 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"); $stmth->bindValue(":uname",$unamel); $stmth->bindValue(":pass",$passl); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); } Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552547 Share on other sites More sharing options...
mac_gyver Posted October 9, 2017 Share Posted October 9, 2017 (edited) 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 October 9, 2017 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/305273-mysql-pdo-not-throwing-exceptions-while-connecting-except-objectpdo1-0/#findComment-1552548 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.