radioactive Posted November 9, 2011 Share Posted November 9, 2011 I want to echo the contents of column 4 for my username only, and it doesn't show anything. I can do if ($memberQuery->fetchColumn(4) < 2) though. $host = 'localhost'; $database = ''; $db_username = ''; $db_password = ''; if (($db = new PDO("mysql:host=$host;dbname=$database", $db_username, $db_password)) == NULL) { echo $db->getMessage(); } $memberQuery = $db->prepare("SELECT * FROM members WHERE username=:username"); $memberQuery->execute(array(':username' => $_SESSION['username'])); $result = $memberQuery->fetchColumn(4); echo "$result"; Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/ Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 Why not just SELECT nameof5thcolumn FROM table WHERE username=:username And then fetchColumn(0) ? Works fine for me. Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286492 Share on other sites More sharing options...
radioactive Posted November 9, 2011 Author Share Posted November 9, 2011 This is my changed code, but nothing is echoing still. $memberQuery = $db->prepare("SELECT expiry FROM members WHERE username=:username"); $memberQuery->execute(array(':username' => $_SESSION['username'])); $result = $memberQuery->fetchColumn(0); echo "$result"; Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286493 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 Perhaps allowing PDO to report errors? $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); This must be before you execute your query though. Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286495 Share on other sites More sharing options...
radioactive Posted November 9, 2011 Author Share Posted November 9, 2011 Nope, it does not echo anything Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286498 Share on other sites More sharing options...
radioactive Posted November 9, 2011 Author Share Posted November 9, 2011 I figured out my problem, I had forgotten to use session_start Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286506 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 To avoid this in the future, please ensure your scripts are reporting all possible errors. A snippet to do this can be found in my signature. This will tell you if you try to use a variable/key that hasn't been declared. Quote Link to comment https://forums.phpfreaks.com/topic/250751-pdo-echoing-column/#findComment-1286755 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.