$editor->db() with nested Select Query
$editor->db() with nested Select Query
From the documentation:
select( string|string[] $table, array $field = "*", array $where = null, array $orderBy = null )
And I have this:
...
->on( 'postCreate', function ( $editor, $id, $values, $row ) {
...
$users = $editor->db()->select( 'user', 'id', 'user = '.$row["user"].' OR (level >= 0 AND level <= 2);' );
...
} )
...
Of course, this is wrong. What I want to ask is what is the correct form to place the parameters with this query in. I can't figure this out >.<
Thanks
This question has an accepted answers - jump to answer
Answers
Its the
where
condition that is tripping you up - the values given as a string there will be escaped in order to prevent SQL injection attacks. What you need to do is build the query more completely since you want to use a condition that isn't a simple equality operator:Its a bit more verbose since you need to call
query
,exec
,fetchAll
, etc yourself, but it does allow more complete control over the query.Allan
Thanks.
Hm... for some strange reason now it's giving me this error (PHP log):
I'm positive the query is correct this time. Any clues what that might be? Sorry
What is the value of
$row['user']
?Could you enable the debug mode (add
->debug( true )
immediately before the->process(...)
method) and then show me the JSON response from the server? It should include the SQL that is executed, which will give us a clue as to what is going wrong.Thanks,
Allan
Here it is the JSON response from the server after debug( true ):
and then this:
Here is the code that is giving me troubles:
If I change the $row['user'] for another integer, it works fine but I need to get the created row user id >.< Sorry for the mess haha!
Formatted JSON:
There is something very odd about the
**
- that makes it invalid JSON...There is something odd happening with the
$row['user']
parameter.Could you show me what the result of:
var_dump( $row['user'] );
is? It will make the JSON return invalid, but it will show what it is. I don't think its an integer, but rather its an object, and that is what is causing the issue.Allan
Don't worry about it. It was probably me messing up the copy/paste/"formatting" of the JSON into the forum
And thank you very much! $row['user'] is indeed an object (well... more like an array). So replacing it with $row['user']['id'] solved the issue!
Thanks again! I learned a few tools for debugging for next time ! Sorry for the bothers xD
Perfect - great to hear you've got it working now.
Allan