0

Maybe the question title isn't very clear but I don't know how to describe.

I'll try to explain:

I have a MySQL query in my PHP code like this:

$statement = $pdo->prepare('SELECT name FROM persons WHERE name = :name');
$statement->execute(array(':name' => "Peter-Loew"));

What I want to to is to edit :name before comparing with "Peter-Loew".

I want to run a PHP code like this on :name before comparing with "Peter-Loew":

<?php
function url_replace($url_replace) {
$url_replace = str_ireplace(array('Ä','Ö','Ü'), array('Ae','Oe','Ue'), $url_replace);
$url_replace = preg_replace('~[^a-zA-Z0-9]+~', '-', $url_replace);
$url_replace = trim($url_replace, '-');
$url_replace = rtrim($url_replace, '-');
return $url_replace;
}
?>

How can I do this? Or, does anybody know how to call this what I'm looking for?

1 Answers1

2

You're looking for mysql REPLACE:

$statement = $pdo->prepare('SELECT name FROM persons WHERE REPLACE(name, " ", "-") = :name');
$statement->execute(array(':name' => "Peter-Loew"));
u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • 1
    I don't understand why you ask for replacing `-` while your real problem is obviously of a different kind? – u_mulder Feb 09 '17 at 21:32
  • @David . . . Your question is quite clear and this answer answers it. If you have *another* question, then ask it as another question. Don't modify this one. That will just invalidate this correct answer, which might draw downvotes. – Gordon Linoff Feb 09 '17 at 21:33
  • Sorry, my fault. I thought there's no way to do this in SQL itself and I wanted to keep the question clear. Sorry! I edited my question. –  Feb 09 '17 at 21:33