我编写了一个PHP脚本来执行从十六进制到RGB和HSL值的一些颜色转换,并将它们存储在数据库中。我目前的数据集是整个Pantone Solid Coated彩色书,它是1341种颜色。我已经在那里有十六进制值。
从那里我访问了数据库并获取了Hex值并完成了两次转换,然后将它们存储回表中。
我没有收到任何错误,但是即使我为测试所做的所有值的回显显示所有1341种颜色都应用了计算,但过程似乎在记录499处停止了更新。
这是我到目前为止的脚本:
// SQL Server Login Info Removed
$sql_connection = new mysqli($sql_server, $sql_username, $sql_password, $sql_database);
if ($sql_connection->connect_error) {
die("Connection Failed: " . $sql_connection->connect_error);
}
$query = "SELECT * FROM coated";
$result = $sql_connection->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$colorname = $row["mapName"];
$hexvalue = $row["hex"];
if ($row["rgb"] == '') {
$rgbvalue = hex2rgb($hexvalue);
} else {
$rgbvalue = $row["rgb"];
}
if ($row["hsl"] == '') {
$hslvalue = hex2hsl($hexvalue);
} else {
$hslvalue = $row["hsl"];
}
//echo "Color: " . $row["mapName"] . " | " . $rgbvalue . " | " . $hslvalue . "<br>";
$wrt_query = "UPDATE coated SET hex='".$hexvalue."', rgb='".$rgbvalue."', hsl='".$hslvalue."' WHERE mapName='".$colorname."'";
if ($sql_connection->query($wrt_query) === true) {
echo "Record for " . $colorname . " updated <br>";
} else {
echo "Error updating record for " . $colorname . "<br>";
}
}
}
数据来自CSV文件。以下是摘录:
pantone-Yellow-C,#fedd00
pantone-Yellow-012-C,#ffd700
pantone-Orange-021-C,#fe5000
pantone-Warm-Red-C,#f9423a
pantone-Red-032-C,#ef3340
pantone-Rubine-Red-C,#ce0058
pantone-Rhodamine-Red-C,#e10098
pantone-Purple-C,#bb29bb
pantone-Violet-C,#440099
pantone-Blue-072-C,#10069f
pantone-Reflex-Blue-C,#001489
pantone-Process-Blue-C,#0085ca
pantone-Green-C,#00ab84
pantone-Black-C,#2d2926
pantone-Yellow-0131-C,#f2f0a1
pantone-Red-0331-C,#fcaebb
pantone-Magenta-0521-C,#f1b2dc
pantone-Violet-0631-C,#bf9bde
pantone-Blue-0821-C,#74d1ea
pantone-Green-0921-C,#9de7d7
pantone-Black-0961-C,#9e978e
...
pantone-Black-2-C,#332f21
pantone-Black-3-C,#212721
pantone-Black-4-C,#31261d
pantone-Black-5-C,#3e2b2e
pantone-Black-6-C,#101820
pantone-Black-7-C,#3d3935
答案 0 :(得分:-1)
您可能需要在php.ini
中提高脚本时间,这里我使用php函数。
我认为十六进制在这里作为一个关键是更可靠的,所以我使用它,因为它总是相同的字段长度。
我已经删除了它的更新,因为你没有改变它。
我也是mysql
if
,因为我偷偷摸摸。
备份你的数据库,然后开始吧。
set_time_limit(10000);
// SQL Server Login Info Removed
$sql_connection = new mysqli($sql_server, $sql_username, $sql_password, $sql_database);
if ($sql_connection->connect_error) {
die("Connection Failed: " . $sql_connection->connect_error);
}
$query = "SELECT * FROM coated";
$result = $sql_connection->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$wrt_query =
"UPDATE coated SET
rgb=IF(rgb IS NULL or rgb='','".hex2rgb($row["hex"])."',rgb)',
hsl=IF(hsl IS NULL or hsl='','".hex2hsl($row["hex"])."',hsl)'
WHERE hex='".$row["hex"]."';";
if ($sql_connection->query($wrt_query) === true) {
echo "Record for " . $colorname . " updated <br>";
} else {
echo "Error updating record for " . $colorname . "<br>";
}
}
}