I'm trying to set the column of a table to a string in every row if the column exists. However, I am receiving SQL syntax errors and can't pinpoint what exactly the issue is:
while($db = mysqli_fetch_array(mysqli_query($conn, "SHOW DATABASES"))){
$id = $db['id'];
$sql = /** @lang text */
"SELECT IF( EXISTS(
SELECT DISTINCT `info`
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('borrower')
AND TABLE_SCHEMA = '$db'))
BEGIN
UPDATE `info`
SET `borrower` = '****'
WHERE `id` = '$id'
END";
$query = mysqli_query($conn, $sql);
if (!$query){
// Deal with error
}
}
The syntax error I receive back:
information_schema
db1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
BEGIN
UPDATE info
SET borrower = '****'
' at line 5
I know it must be something very small but I have been stuck for a while and can't seem to find my error.