PHP: get file status, get MySQL table status
Blogs20112011-10-02
PHP: get File Status?
The following PHP function get server-side file stats, and present the file stats(accessed, modified, created) in webpage:
function get_file_stat($file)
{
$ss = @stat(PATH.$file);
if(!$ss) return false;
return array(
'accessed'=>@date('Y M D H:i:s',$ss['atime']),
'modified'=>@date('Y M D H:i:s',$ss['mtime']),
'created'=>@date('Y M D H:i:s',$ss['ctime'])
);
}
// loop 'PATH' directory to get all files' stats,
// keep them in an associated array.
if (is_dir(PATH)) {
$dir_res = opendir(PATH);
while ($file=readdir($dir_res)) {
if ($file=='..' || $file=='.') continue;
$files[$file] = get_file_stat($file);
}
}After the processing, all filesās stats under the āPATHā directory is collected into $files array.
PHP: get MySQL table status
How to collect MySQL table information? such as table created, updated, author etc?
$query = array(
"SHOW TABLE STATUS FROM testdb WHERE name = 'table1'",
"SHOW TABLE STATUS FROM testdb WHERE name = 'table2'",
"SHOW TABLE STATUS FROM testdb WHERE name = 'table3'",
"SHOW TABLE STATUS FROM testdb WHERE name = 'table4'"
);
foreach ($query as $sql) {
$result = mysql_query($sql);
$info[] = mysql_fetch_assoc($result);
}
mysql_free_result($result);
return $info;
//All the table's information is kept to $info array.
//Such as table updated time:
// $info[0]['Update_time'];Above are the methods to collect Server-side files and MySQL Tables information. Sometimes they are very useful.
