Instantly share code, notes, and snippets.

Embed
What would you like to do?
[PHP] Using sprintf and LIKE in SQL Queries in WordPress
<?php
/**
* Queries a third-party API using sprintf and a LIKE clause to retrieve the users
* with a last name like the specified argument.
*
* @param string $lastName An unsanitized version of the user's last name.
*/
public function getUserByLastName(string $lastName)
{
// Sanitize the argument as you see fit here.
$query = sprintf("
SELECT FIRST_NAME, LAST_NAME
FROM USERINFO
WHERE LAST_NAME LIKE '%%%s%%'
", $lastName);
// Make a query to the third-party API here.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment