Welcome Guest, Not a member yet? Register   Sign In
MOVED - When passing variable to DB statement value is changing
#1

[eluser]RJ[/eluser]
Hi,

Having a problem, when I set class variables from input and print the results they are as expected:
Code:
$this->MSISDN = $this->input->post('MSISDN');
$this->UNITID = $this->input->post('UNITID');

print($this->UNITID);
print($this->MSISDN);

But when I add those to the query below the values are changed to '1'??
Code:
$TT->select('devicetype');
$TT->select('TO_CHAR(subversion)', FALSE);
$TT->where(array(
            'msisdn' => $this->input->post('MSISDN'),
            'unitid' => $this->UNITID
        ));
$query = $TT->get('ttdevice');

Even when I try directly from post, the result is below:
Quote:SELECT devicetype, TO_CHAR(subversion)
FROM (ttdevice)
WHERE msisdn = '1'
AND unitid = '1'

Any idea why this is occurring and how to fix?

Thank you.

EDIT
The only way I can get something other than '1' to pass is by hard coding like below:
Code:
$TT->where(array(
            'msisdn' => 123456,
            'unitid' => $this->UNITID
        ));

Note no '123456' quotes around the numbers, if there are quotes it doesn't work; other variations of the query I've tried with the same result:
Code:
//Active Record Method Chaining
$TT->select('devicetype')->select('TO_CHAR(subversion)', FALSE)->where('msisdn', $this->MSISDN)->where('unitid', $this->UNITID);

// remove the where array
$TT->select('devicetype');
$TT->select('TO_CHAR(subversion)', FALSE);
$TT->where('msisdn', $this->MSISDN);
$TT->where('unitid', $this->UNITID);
#2

[eluser]RJ[/eluser]
I settled with this query:
Code:
$query = $TT->query("SELECT devicetype, TO_CHAR(subversion) FROM ttdevice WHERE msisdn = '".$this->MSISDN."' AND unitid = '".$this->UNITID."'");

Just can't get the damn thing to return any results.

Submitting now
Code:
$query = $TT->query("SELECT * FROM ttdevice");
show_error($query->num_rows());

the result is -1. I know the db is there, am i missing something?
#3

[eluser]RJ[/eluser]
Object results
Quote:CI_DB_odbc_result Object ( [conn_id] => Resource id #123 [result_id] => Resource id #124 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => -1 [row_data] => )
#4

[eluser]jedd[/eluser]
What does the profiler reveal about your actual query?

I can recommend formatting your ->query stuff to make it more readable - syntax bugs stand out much more obviously, eg.
Code:
$query = $this->db->query ("SELECT  message.id AS message_id,
                                            member.login_name AS addressee_name,
                                            message.subject,
                                            message.msgdate,
                                            member.login_name as author_name
                                        FROM
                                            message
                                        LEFT JOIN
                                            member ON message.author=member.id
                                        WHERE
                                            addressee=". $my_id ."
                                        ORDER BY
                                            message.msgdate DESC
                                        LIMIT ". $offset ." , ". $count );

Btw, been meaning to ask for some time, but is the misspelling in your sig some post-modern or ironical reference to enjoying bad-writing?
#5

[eluser]RJ[/eluser]
In all instances the profiler will not display the odbc query, not sure why. I am using multiple databases, default is an sql that does show up in the profiler; when I run this other query, which is a form_validation callback method, it does not show.

I moved the thread to here when I finally was able to find the results.. num_rows check is screwing it all up. http://ellislab.com/forums/viewthread/111959/

Good suggestion.

Nope, user error! LOL, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB