duanhe4267 2010-02-11 13:55
浏览 21
已采纳

通过PHP更新MySQL中的文件路径不起作用

I am storing network share paths in my table in MySQL. but some entries got corrupted, i.e they dont have any backslashes in between. Path is like a big word. I wrote a small script in PHP to update these paths to try and add slashes. It does not give me any error when I run it but the results are not getting updated in the table.

Currently the path in my tables is like this: \fil01logsTestDat1oop_s2010Log and I want to make it \\fil01\logs\Test\Dat1\oop_s\2010\Log

If I echo the last $ch7 the results is what I want but it is not going into the table.

$result = mysql_query("select dbresultsid,ResultDirectory from results where dbresultsid > 48717") or die(mysql_error());  
$i= 0;
// store the record of the "example" table into $row
while($row = mysql_fetch_array( $result )) {

$ch = $row['ResultDirectory'];
$id  = $row['dbresultsid'];


if(strstr($ch, $fsd))
{
//echo 'Yes'.$i.'<br>';
//$i++;
$ch1 = str_replace("fil01","\\fil01\\",$ch);
$ch2 = str_replace("logs","logs\\",$ch1);
$ch3 = str_replace("Test","Test\\",$ch2);
$ch4 = str_replace("Dat1","Dat1\\",$ch3);
$ch5 = str_replace("oop_s","oop_s\\",$ch4);
$ch6 = str_replace("2010","2010\\",$ch5);
$ch7 = str_replace("Log","\\Log",$ch6);
//echo trim($ch7).'<br>';
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("opp") or die(mysql_error());
echo "Updating $id with $ch7 <br>";
$update_again = mysql_query("update results set ResultDirectory = \"$ch7\" where dbresultsid = \"$id\" ") or die(mysql_error());  
echo "Updated record $i <br>";
$i++;
}

}

?>

Any ideas?

Thanks.

  • 写回答

2条回答 默认 最新

  • doucha7329 2010-02-11 14:46
    关注

    I got it resolved. The only setting I had to make was this :

    $set = mysql_query("set sql_mode='NO_BACKSLASH_ESCAPES';");

    before updating.

    Hope this helps others.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体