× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
db where var1=x AND var2=y AND var3=q
I can't figure out how to solve a right query, what do I wrong?

sql query: 
DELETE FROM `tbl_resource` WHERE (`ID_resource`=".$var1."  AND `ID_veld`=".$var2." AND `type_resource`='P') LIMIT 1;

first try:
[ "AND", 
["ID_veld", "=", $lesblokId ],
["type_resource", "=", "P"]

second try:
[ "AND", 
[ "AND",[
["ID_veld", "=", $lesblokId ]
["type_resource", "=", "P"]
fallback scenario below used, but please let me know what's the best way to work ;-)

$db->query("DELETE FROM `tbl_resource` WHERE (`ID_resource`= ? AND `ID_veld`= ? AND `type_resource`='P') LIMIT 1;",[$papoId, $lesblokId]);
What happens if you do
$db->query("DELETE FROM tbl_resource WHERE ID_resource = ? AND ID_veld= ? AND type_resource=? LIMIT 1",[$papoId, $lesblokId,'P']);
And btw, table name is really tbl_resource not resource and the columns are ID_veld not veld right?
(01-06-2019, 01:19 AM)mudmin Wrote: And btw, table name is really tbl_resource not resource and the columns are ID_veld not veld right?

the normal query works (my second post-entry), but was wondering why it should not work like my try in a first manner.

but I understand it only works for two variables or isn't it so?
Hi. Sorry. Pretty much all the devs have been away this weekend. Sorry for the slow response.

As far as the first vs second, I'll take another look. the way I wrote the query is shorter. In general if you can avoid the paranthesis and ` vs ' there are fewer chances for a mistake.

Ready for something that will change your life and I went 2 years without knowing? ...
After your query that doesn't work, you can just type
dump($db->errorInfo()); and you will get PDO's best guess as to what's wrong with your query. If you get some array with just 012, that means it worked as far as PDO/MySQL is concerned.

You can bind as many variables as you want with the ? thing if that's what you're talking about. And you really don't have to bind that P, like I moved from the query to the bound parameters, but I always do it in case I want to sub it out with a variable later.

I think the $db->delete only works with one parameter. I usually only use that with an ID. I like to write out my delete queries, personally.

Forum Jump:

Users browsing this thread: 1 Guest(s)