存档

文章标签 ‘mysql’

数据复活

2009年4月10日 李悦 没有评论

  某个系统管理员一不小心直接用数据库管理工具把一文章表的标题字段类型改了,导致所有文章标题不能正常显示了。上万条的数据有点懵了。之前数据库也没有备份过。试图修复数据库也没有成功。唯一的希望寄托在数据库本身的结构上。
  由于文章的部分信息在另外一个表中也有所体现,标题信息正在其中。只要将这部分信息重写回表中就可以恢复。两个表是通过ID相关联的。检索出文章对应的标题并写回原表。但是原表文章范围大于另一个表,只要少量信息不存在。能恢复大部分信息就好了。

<?php
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "password";
$DB_DBName = "dbname";
//$DB_TBLName = "column_article";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect.");
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database.");
 
$sql = "Select column_article.title,column_article.articleid,article.title,article.id from column_article,article where column_article.articleid=article.id";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database");
 
$result = @mysql_query($sql,$Connect)
or die(mysql_error());
 
$i = 0;
while($row = mysql_fetch_row($result))
{
$title2=$row[0];
$title2id=$row[1];
$upd = @mysql_query("update article set article.title='$title2' where article.id=$title2id",$Connect);
$i++;
}
return (true);
?>
分类: 系统 标签: ,

将mysql检索结果导出EXCEL表

2008年12月5日 李悦 没有评论

说明:数据表fawen是文件的标题,正文等信息,数据表pishi是各领导对文件的批示信息,pishi的articleid字段内容与fawen的id相关联。要统计出某位领导的所有批示,导出EXCEL,内容是:文件名称、批示内容、批示时间。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "pass";
$DB_DBName = "office";
$DB_TBLName = "fawen";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect.");
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database.");
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=mydowns.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
$now_date = date('Y-m-d H:i');
$title = "格式:第一列为文件名,第二列为领导批示内容,第三列为批示日期";
$sql = "Select $DB_TBLName.title,pishi.content,pishi.time from $DB_TBLName,pishi where pishi.leadername='领导名称' and $DB_TBLName.id=pishi.articleid";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database");
 
 
$result = @mysql_query($sql,$Connect)
or die(mysql_error());
 
$result2 = @mysql_query($sql2,$Connect)
or die(mysql_error());
 
echo("$titlen");
$sep = "t";
//for ($i = 0; $i < mysql_num_fields($result); $i++) {
//echo mysql_field_name($result,$i) . "n";
//}
print("nnn");
$i = 0;
 
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert .= "t";
print(trim($schema_insert));
print "nnnn";
$i++;
}
return (true);
?>
分类: 系统 标签:

数组的应用

2008年10月20日 李悦 没有评论

  对已知数目的查询条件,使用数组定义,然后遍历数组,使用while循环查询符合数组数值条件的记录,并统计。
  片段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
		//数组
		$workArray = array("办公室", "财务基建", "人事处", "老干部处", "机关党委","纪检监察","综合处","核算处","政法处","工业处","能源处","农村处","国贸处","外经处","投资处","服务业处","人口处","社科处","普查中心","基普办","科研所","计算中心","教育中心","记者站","印刷厂"); 
 
			while  (list($key,$value) = each($workArray))  {
				$z--;
				$sql5="select count(id) as id from art where author='$value' and createdate>='$starttime' and createdate <='$endtime'";
				$r5= $DB_web->query_first($sql5);
 
				print "<tr bgcolor='#DDDDDD'>";
				print "<td height='20'>&nbsp;$value</td>";
				print "<td height='20'>&nbsp;$r5[id]</td>";
        print "</tr>";
 
			}
分类: 系统 标签: ,

mysql最大连接数

2008年8月7日 李悦 没有评论

  在linux下修改mysql最大连接数,网上说修改/etc/my.cnf文件。在[mysqld]段加入 max_connections =1000一行参数。结果导致启动失败。后来改成set-variable   = max_connections =1000成功。

  还有将/etc/my.cnf权限改成644。

分类: 系统 标签: