在我的表格中,我有大約120個url(主鍵)。現在我增加了一個列hash
這需要這樣使用當前行值的值更新表格
$hash = md5($url);
我想刪除URL的哈希值作爲主鍵(我做到了),並設置散列作爲主鍵。
當前,當我嘗試使散列作爲主鍵,說dublicate條目錯誤。因爲哈希的所有120條目都是空的。
所以我想更新我的表,使散列應設置爲散列= md5(url)。
我嘗試:
<?php
$con = mysqli_connect('127.0.0.1', 'root', '', 'mysql');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$result = mysqli_query($con,"SELECT url from frrole_cateogry_article");
while ($row = @mysqli_fetch_array($result))
{
$url = $row['url'];
$hash = md5($url);
$update = "UPDATE table frrole_cateogry_article set hash='".$hash."' where url = '".$url."'";
if (!mysqli_query($con,$update))
{
//die('Error: ' . mysqli_error($con));
echo "error";
}
}
?>
錯誤消息die('Error: ' . mysqli_error($con));
是
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table frrole_popular_article set hash='3402a8ee11df088cd4e4a270dacbcc98' where u' at line 1
但它給錯誤回聲error
消息。
出了什麼問題?
爲什麼你註釋掉了'mysqli_error($ con)'?這可以告訴很多 –
爲什麼不將自動ID列設置爲主鍵,然後更改所有散列? –
顯示你的錯誤信息... – user1844933