Welcome Guest, Not a member yet? Register   Sign In
Working with Clobs
#1

[eluser]imorris[/eluser]
I'm having trouble pulling a clob back from an Oracle database. I'm not sure what I have to do to handle the clob ('W.DESCRIPTION' in this case).

Here's what is in my Model:

Code:
function get_last_ten_changes()
    {
        $this->db->select('A.ASSETNAME, W.DESCRIPTION');
        $this->db->from('WORKORDER W');
        $this->db->join('ASSET A', 'W.ASSETID = A.ID','inner');
            $this->db->where('W.CHANGEREQUEST', '1');
        $this->db->limit(10);
        $query = $this->db->get();
        return $query;
    }

Here is the error I'm getting:

Code:
A PHP Error was encountered
Severity: 4096

Message: Object of class OCI-Lob could not be converted to string

Filename: views/welcome_message.php

Line Number: 62


Any suggestions?
#2

[eluser]techgnome[/eluser]
Judging by the error coming back from the view, I'd say it has something to do with how CI takes the associative array and converts it to variables you can use in your view.

Once you get the data from the model, how are you passing it to the view? (in other words, what does the controller look like?) There maybe a couple ways around it.

-tg
#3

[eluser]imorris[/eluser]
Here's the function in my controller
Code:
function index()
    {
        $this->load->model('change_management_model');
        $data['last_ten'] = $this->change_management_model->get_last_ten_changes();
        $this->load->view('welcome_message',$data);
    }

Here's how I'm looping through the query results in my view
Code:
foreach ($last_ten->result() as $app)
        {
            ?>
            <tr>
                <td>&lt;?php echo $app->ASSETNAME;?&gt;</td>
                <td>&lt;?php echo $app->DESCRIPTION;?&gt;</td>
            </tr>
           &lt;?php } ?&gt;
#4

[eluser]imorris[/eluser]
The problem was that I needed to adjust how I was echo-ing out the DESCRIPTION result in my loop. I needed to change it from:

Code:
<td>&lt;?php echo $app->DESCRIPTION;?&gt;</td>

to
Code:
<td>&lt;?php echo str_replace("\r", "<br/>",$app->DESCRIPTION->load());?&gt;</td>

We added the str_replace because we wanted to keep the carriage returns that weren't displaying properly from the clob.

Can someone tell me what the ->load() method is doing in this situation and why this works?




Theme © iAndrew 2016 - Forum software by © MyBB