问题描述
|
这个问题已经在这里有了答案:
解决方法
您在第一个选择语句上遇到mysql错误,
\"SELECT * FROM \".$dbsite.\"_categories\"
表名必须格式错误。确认存在“ 1”。
如果是这样,请尝试以下操作:
$l = mysql_connect($host,$user,$pwd);
mysql_select_db($base);
$sql = \"SELECT * FROM arfooo_categories\";
$result = mysql_query($sql);
echo $result ? \'all good\' : mysql_errno($l) . \': \' . mysql_error($l) . \"\\n\";
,您需要检查是否已建立连接
$mysql_link = mysql_connect($host,$pwd);
if (!$mysql_link) {
echo \"Couldn\'t connect to the database. Check your credentials\";
die();
}
//code
$result = mysql_query($sql);
if (!$result) {
echo \"Oops,something seems to be wrong.\";
die();
}
,我建议尝试一下。您需要准确确定错误的出处。
<?php
// remplacer par vos valeurs de connexion
$host=\"*****\";
$user=\"*****\";
$pwd=\"******\";
$base=\"*****\";
$mysql_link = mysql_connect($host,$pwd);
if (!$mysql_link) {
die(mysql_error());
}
$db_name = mysql_select_db($base);
if (!$db_name) {
die(mysql_error());
}
$dbsite=\"arfooo\"; // prefixe de votre table sans \"_\" par exemple : \"arfooo\"
$sql = \"SELECT * FROM \".$dbsite.\"_categories\";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_object($result)) {
$depth=0;
echo \"INSERT INTO `\".$dbsite.\"_categoryparents` (`parentId`,`childId`,`depth`) VALUES ($row->categoryId,$row->categoryId,$depth);<br>\\n\";
$parentId = $row->parentCategoryId;
while ($parentId<>0){
$sql2 = \"SELECT * FROM \".$dbsite.\"_categories WHERE categoryId = $parentId\";
$result2=mysql_query($sql2);
while ($row2=mysql_fetch_object($result2)) {
$depth=$depth+1;
echo \"INSERT INTO `\".$dbsite.\"_categoryparents` (`parentId`,`depth`) VALUES ($row2->categoryId,$depth);<br>\\n\";
$parentId = $row2->parentCategoryId;
}
}
$depth=$depth+1;
echo \"INSERT INTO `\".$dbsite.\"_categoryparents` (`parentId`,`depth`) VALUES (0,$depth);<br>\\n\";
}
?>