Welcome Guest, Not a member yet? Register   Sign In
What does Active record return
#1

[eluser]minerbog[/eluser]
Hi Guys,

I have looked at the source but it isn't completely obvious! Well not to me!!

From what I can find out in the code, the $this->db->update() function returns a sql statement. But when in my code I grab the return to a variable and echo it, it shows 1.

Now I've never managed to echo an error yet as CI always displays it's main DB error message, but I am assuming that on an error it would return 0??

Also, if this is that case, is that the same for all write functions??

Many Thanks

Gavin.
#2

[eluser]InsiteFX[/eluser]
It returns 1 = TRUE or 0 = FALSE if the update succeed.

If you want the string version see the query helper functions...

#3

[eluser]minerbog[/eluser]
[quote author="InsiteFX" date="1333894540"]It returns 1 = TRUE or 0 = FALSE if the update succeed.

[/quote]

Assume you mean 1=TRUE is succeeded or 0=FALSE if failed??
#4

[eluser]InsiteFX[/eluser]
Correct.

For all other Active Records use this for testing the retruned value, you can set it to TRUE or FALSE.
Code:
// your query here:

if ($query->num_rows() > 0)
{
    // your code
    return your_result;
}

return FALSE;

#5

[eluser]smilie[/eluser]
Just for the good order, Active Class returns boolean type, as already explained 1 or 0, TRUE or FALSE;

I am telling this, just because you can also do stuff like this;

Code:
$result = $this->db->get()->result_array();
if($result) { ... }

Meaning, if there is any result, $result will be TRUE (or 1);

Cheers,
Smilie
#6

[eluser]Matalina[/eluser]
actually what you say smilie is not true. if you add result_array, if there are results it will be an array of results which is true in an if statement. result_array() will return false if it is empty.
#7

[eluser]smilie[/eluser]
@Matalina,

Eh, well - what I meant is that array() per definition is not FALSE; in bool it can then only be TRUE.
And indeed if TRUE, array will have some data.

But the point remains, that in the if() statement array will be interpreted as TRUE - that was my point.

Cheers,
Smilie
#8

[eluser]Matalina[/eluser]
[quote author="smilie" date="1334071868"]@Matalina,

Eh, well - what I meant is that array() per definition is not FALSE; in bool it can then only be TRUE.
And indeed if TRUE, array will have some data.

But the point remains, that in the if() statement array will be interpreted as TRUE - that was my point.

Cheers,
Smilie[/quote]

I know. But I wanted to clarify for the OP just in case.




Theme © iAndrew 2016 - Forum software by © MyBB