William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

PHP: get file status, get MySQL table status

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.

Advertisements

2 responses to “PHP: get file status, get MySQL table status

  1. Coleen Vernia 10/21/2011 at 7:32 am

    I like the helpful information you provide in your articles. I will bookmark your weblog and check again here regularly. I’m quite certain I’ll learn lots of new stuff right here! Best of luck for the next!

  2. powercashadvance.com 10/26/2011 at 4:48 pm

    It is rare to discover a professional in whom you can have some faith. In the world at present, nobody truly cares about showing others exactly how in this issue. How happy I am to have now found a really wonderful web page as this. It is really people like you exactly who make a true difference in this world through the ideas they talk about.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: