*** is marked as crashed and should be repaired
宝塔面板 里的 数据库修复不管用。就不出现这个表。要到shell权限后,登录到linux:
执行命令 myisamchk -c -r /www/server/data/www_sfyear_com/pre_forum_thread.MYI
错误
myisamchk: error: 140 when opening MyISAM-table
百度的结果是
这是Mysql5.6的一个Bug 去掉.MYI即可
改用命令:myisamchk -c -r /www/server/data/www_sfyear_com/pre_forum_thread
有反馈了:
- recovering (with sort) MyISAM-table '/www/server/data/www_sfyear_com/pre_forum_thread'
Data records: 8686
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
- Fixing index 6
- Fixing index 7
- Fixing index 8
- Fixing index 9
- Fixing index 10
然后,然后就好了 。
以下为数据库访问代码备用:
<?php
//数据库设置
$servername = "localhost";
$username = "root";
$password = "******";
$dbname = "empirecms103075";
$tbname='phome_ecms_news';
//字段设置
$id='id';
$newstext='title';
$num=0; //总数,如果不设置会每次都重新统计,影响效率
//连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (mysqli_connect_errno($conn))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
if(!$num){
$sql="select count(*) as total from $tbname";
$result=mysqli_query($conn,$sql);
$numr=mysqli_fetch_array($result,MYSQLI_ASSOC);
$num=$numr['total'];
mysqli_free_result($result);
}
// 取第一条为标题
$sql="select $newstext from $tbname where $id=1";
$result=mysqli_query($conn,$sql);
$r=mysqli_fetch_array($result,MYSQLI_ASSOC);
$title=$r[$newstext];
mysqli_free_result($result);
//
$rand_title='';
while(!$rand_title){
$randid=rand(2,$num);
$sql="select $newstext from $tbname where $id=$randid";
$result=mysqli_query($conn,$sql);
$r=mysqli_fetch_array($result,MYSQLI_ASSOC);
$rand_title=$r[$newstext];
mysqli_free_result($result);
}
echo $rand_title;
//释放资源
mysqli_close($conn);
// 模板你自己写,$title 是固定标题 $rand_title是随机的
?>