Jump to content

Processing data with PDO


rdkurth

Recommended Posts

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;

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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}]}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.