我想在MySQL表中的一列中搜索由变量定义的字符串。该语法看起来如何做到这一点?
我在脑海中的想象:
$var = 'this is a string';
$query = 'SEARCH column IN table for ' . $var;
如果找到,将使用PHP将数字附加到字符串中,$var
将变为:
$var = 'this is a string2';
这是怎么做到的?感谢
$str = "this is a string";
$getstringexists = mysql_query("SELECT * FROM table WHERE column LIKE '$str'", $connection);
$string_exists = mysql_num_rows($getstringexists);
if($string_exists){
$str .= "$sting_exists";
}
以自己的方式连接到数据库,我总是在包含数据库信息的查询末尾使用$connection这样的变量。
如果查询返回5行,则应使新的$str等于"this is a string5";