1

I'm trying to execute the following mysqli statement:

SHOW TABLE STATUS LIKE 'QUESTIONS'

I want to loop through the result and find and return the value of Update_time.

I have found some examples on the web but can't get them to work within my PHP script.

My other PHP functions follow the following format and I'd like this function to match it.

public function getQuestionsSections() {
 $stmt = mysqli_prepare($this->connection,
      "SELECT DISTINCT
          QUESTIONS.SECTION
       FROM QUESTIONS");     

  $this->throwExceptionOnError();

  mysqli_stmt_execute($stmt);
  $this->throwExceptionOnError();

  $rows = array();
  mysqli_stmt_bind_result($stmt, $row->SECTION);

  while (mysqli_stmt_fetch($stmt)) {
      $rows[] = $row;
      $row = new stdClass();
      mysqli_stmt_bind_result($stmt,  $row->SECTION);
  }

  mysqli_stmt_free_result($stmt);
  mysqli_close($this->connection);

  return $rows;
}

I'd really appreciate some help in writing the php function as I'm not a php programmer.

An answer to the problem is presented here,

Having trouble displaying last update time of mySQL table

Unfortunately it doesn't work for me. It would be ideal if we used the mysqli_prepare as above

4

1 に答える 1

0
  SHOW TABLE STATUS LIKE  'QUESTIONS'

同等です

 SELECT UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_NAME LIKE 'QUESTIONS'

. UPDATE_TIME (Update_time ではない) を取得するには、「information_schema」データベースにアクセスする必要があります。

public function getStatus() {

 $con = mysqli_connect("localhost","root","password","information_schema");
 $stmt = mysqli_prepare($con ,
      "SELECT UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_NAME LIKE 'QUESTIONS'");     

  mysqli_stmt_execute($stmt);

  $rows = array();
  mysqli_stmt_bind_result($stmt, $row->UPDATE_TIME );

  while (mysqli_stmt_fetch($stmt)) {
      $rows[] = $row;
      $row = new stdClass();
      mysqli_stmt_bind_result($stmt,  $row->UPDATE_TIME );
  }

  mysqli_stmt_free_result($stmt);
  mysqli_close($con);

  return $rows;
 }

私はそれがうまくいくことを願っています。

参照: https://dba.stackexchange.com/questions/3221/how-to-select-from-show-table-status-results

于 2012-07-20T12:33:01.207 に答える