Home  >  Article  >  Backend Development  >  Php query by time Mysql common statements

Php query by time Mysql common statements

WBOY
WBOYOriginal
2016-07-25 09:13:211114browse

We often see some historical data on today or by year and month, and we need to use time query. Query by time, where Ymd represents the year, month and day respectively. Of course, you can also use one of the time items for flexible use.

1. Query this month’s data:

  1. (date_format(time field,'%Y%m%d')=date_format(DATE_SUB(curdate(), INTERVAL 0 MONTH),'%Y%m%d''))
Copy Code

2, query the data of the previous month: (where 1 represents the previous month)

  1. (date_format(time field,'%Y%m%d')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y%m%d''))
Copy Code

Some commonly used PHP statements to operate mysql:

  1. //Query statement

  2. $query = "SELECT * FROM table";
  3. $resul = mysql_query($query) or die('SQL statement is incorrect:'.mysql_error()) ;
  4. $user = mysql_fetch_array($resul);
  5. //Loop query statement
  6. $query=mysql_query("select * FROM table");
  7. while($table = mysql_fetch_array($query)){
  8. //Loop Displayed content...
  9. }
  10. //New statement
  11. $query = "INSERT INTO table(aaa,bbb) VALUES ('$aaa','$bbb')";@mysql_query($query) or die ('New error:'.mysql_error());
  12. //Update statement
  13. $query = "UPDATE table SET aaa='$aaa',bbb='$bbb' WHERE id='$id'";
  14. @mysql_query($query) or die('Modify error:'.mysql_error());

  15. //Delete statement

  16. $query = "DELETE FROM table WHERE id='$deleteid'" ;
  17. $result = mysql_query($query) or die('SQL statement error:'.mysql_error());

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn