Skip to content

Instantly share code, notes, and snippets.

@ivanionut
Forked from mpadmore/ExampleQuery.cfm
Created June 3, 2018 16:24
Show Gist options
  • Save ivanionut/518a2e4baf1c6c7c49889d88808a2913 to your computer and use it in GitHub Desktop.
Save ivanionut/518a2e4baf1c6c7c49889d88808a2913 to your computer and use it in GitHub Desktop.
Example of queryExecute
<cfscript>
people = queryNew(
"id, firstName, lastName, email, country, ip_address",
"integer, varchar, varchar, varchar, varchar, varchar",
[{
"id": 1,
"firstName": "Christopher",
"lastName": "Burton",
"email": "[email protected]",
"country": "Poland",
"ip_address": "81.248.29.126"
}, {
"id": 2,
"firstName": "Scott",
"lastName": "Vasquez",
"email": "[email protected]",
"country": "Iceland",
"ip_address": "225.10.179.213"
}, {
"id": 3,
"firstName": "Earl",
"lastName": "Berry",
"email": "[email protected]",
"country": "Sri Lanka",
"ip_address": "110.242.80.67"
}, {
"id": 4,
"firstName": "Brian",
"lastName": "Turner",
"email": "[email protected]",
"country": "China",
"ip_address": "140.86.69.145"
}, {
"id": 5,
"firstName": "Jimmy",
"lastName": "Mccoy",
"email": "[email protected]",
"country": "Vietnam",
"ip_address": "215.144.2.198"
}, {
"id": 6,
"firstName": "Bruce",
"lastName": "Williams",
"email": "[email protected]",
"country": "Russia",
"ip_address": "130.107.175.112"
}, {
"id": 7,
"firstName": "Peter",
"lastName": "Cox",
"email": "[email protected]",
"country": "United States",
"ip_address": "155.3.57.239"
}, {
"id": 8,
"firstName": "Edward",
"lastName": "Cook",
"email": "[email protected]",
"country": "France",
"ip_address": "253.187.203.194"
}, {
"id": 9,
"firstName": "Christopher",
"lastName": "Burns",
"email": "[email protected]",
"country": "Indonesia",
"ip_address": "198.207.147.137"
}, {
"id": 10,
"firstName": "Phillip",
"lastName": "Duncan",
"email": "[email protected]",
"country": "China",
"ip_address": "153.44.71.214"
}]
);
writeDump(people);
// CF11+ or Lucee
filterA = "China";
filterB = "P%";
peopleQ2 = queryExecute(
"SELECT * FROM people WHERE country = :country",
{country: filterA},
{dbType:"query"}
);
writeDump(peopleQ2);
peopleQ3 = queryExecute(
"SELECT * FROM people WHERE firstname LIKE :firstname",
{firstname: filterB},
{dbType:"query"}
);
writeDump(peopleQ3);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment