MySql代码
SELECT replace(replace(v.image_path,"\\","/"),"%s","_120") as image_path
FROM `artistkr_fox`.`phpfox_video` v;
我的phpfox服务文件查询字符串
$ aVideos = $ this-> database() - >选择(" REPLACE(更换(v.image_path,' \',' /' ),'%s',#130; _120')as image_path" .phpfox :: getUserField()) - > from($ this-> _sTable,' v') - >执行(' getSlaveRows&#39);
此查询无法返回任何值
错误抛出此代码" REPLACE(v.image_path,' \',' /')"
答案 0 :(得分:1)
您需要确保不要混合使用PHP字符串和SQL查询的引号。
您可以通过在引号前使用反斜杠转义它们来做到这一点(\'
)
$query = 'SELECT replace(replace(v.image_path,"\\","/"),\'%s\',\'_120\') as image_path FROM artistkr_fox.phpfox_video v';
或对PHP字符串使用双引号("
)和SQL查询使用单引号('
):
$query = "SELECT replace(replace(v.image_path,'\\\\','/'),'%s','_120') as image_path FROM artistkr_fox.phpfox_video v";
(注意当PHP字符串使用双引号时,你需要在我们的SQL查询中转义反斜杠)
您选择哪一个取决于您的偏好和情况(例如查询的复杂性)。