-
-
Save tommcfarlin/b4d5a391024b151667fe99f5bd913544 to your computer and use it in GitHub Desktop.
[PHP] Using sprintf and LIKE in SQL Queries in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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