rdkurth Posted February 5, 2014 Share Posted February 5, 2014 This script is running thru without any errors but it is not producing any data but the database is full of data. What am I doing wrong. I am trying to understatnd PDO with MYSQLI <?php include("connect.php"); $pid = $_SESSION['profile']['id']; $sql ="SELECT * FROM signings WHERE pid = \"$pid\" AND done= 0"; $result = $db->query($sql); $out = array(); // Parse the result set foreach($result as $row) { $out[] = array( 'id' => $row->id, 'title' => $row->lname, //'url' => Helper::url($row->id), 'start' => strtotime($row->signstart), 'end' => strtotime($row->signend) ); } echo json_encode(array('success' => 1, 'result' => $out)); exit; Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 5, 2014 Share Posted February 5, 2014 you need to tell us what it is producing as output as that will narrow down the possibilities, even a blank screen is an important clue. your code has no apparent error checking logic in it. the easiest method is to enable exceptions after you make the database connection, then use a try/catch block to handle runtime errors. also, do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would be reporting and display any errors it detects? Quote Link to comment Share on other sites More sharing options...
rdkurth Posted February 5, 2014 Author Share Posted February 5, 2014 I no about using try/catch block and yes I have the E_ALL and display_errors set to ON but this is just a test script to see how to fill in the area. What is happing is it is not passing any info from the database, It looks like the problem is in my select statment but I can not figure out way. This is what I am getting no data at all but there is four records it just not giving me the data. {"success":1,"result":[{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false}]} Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 5, 2014 Share Posted February 5, 2014 all the null/false values are because the data isn't being fetched as an object (there would be php errors like Notice: Trying to get property of non-object in ..., so you don't have php's error reporting set). have you configured pdo to fetch the data as an object? you either need to do that or use array notation to reference the $row values. Quote Link to comment Share on other sites More sharing options...
rdkurth Posted February 5, 2014 Author Share Posted February 5, 2014 oops I forgot I took Notice off error handling the other day. I'm bad!! this is the error Notice: Trying to get property of non-object I am new with PDO so I don't understand alot about it but what I have seen I like. What do you mean by "have you configured pdo to fetch the data as an object" and what are array notation Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 5, 2014 Share Posted February 5, 2014 What do you mean by "have you configured pdo to fetch the data as an object" i recommend that you read/scan through the pdo section of the php.net documentation so that you are aware of the different things it can do. and what are array notation again, this is the basics and array variables would be/are covered within the first few chapters of the php.net documentation, a basic php book, tutorial, or class. Quote Link to comment 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.