简体   繁体   English

MySQL,PHP; 比较前编辑列值

[英]MySQL, PHP; Edit column value before comparing

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: 我的PHP代码中有一个MySQL查询,如下所示:

$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" . 我想要做的是在与"Peter-Loew"比较之前先编辑:name

I want to run a PHP code like this on :name before comparing with "Peter-Loew" : 在与"Peter-Loew"比较之前,我想在:name上运行这样的PHP代码:

<?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? 或者,有人知道该如何称呼我正在寻找的东西吗?

You're looking for mysql REPLACE : 您正在寻找mysql REPLACE

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM