MySQL Delete and change tool PHP class

Source: Internet
Author: User
Tags mysql delete php class
  1. Previous development projects did not use a framework, directly object-oriented development of a very useful MySQL tool class.
  2. Header ("Content-type:text/html;charset=utf-8");
  3. Class dbutils{
  4. /**
  5. * Generic Update method Insert Update Delete operation
  6. * @param sql
  7. * @return bool True False
  8. */
  9. Public Function Update ($sql) {
  10. $link = $this->getconn ();
  11. mysql_query ($sql);
  12. If an error is displayed
  13. if (DEBUG) {
  14. Echo Mysql_error ();
  15. }
  16. $rs = Mysql_affected_rows ($link);
  17. $rs = $rs > 0;
  18. Mysql_close ($link);
  19. return $rs;
  20. }
  21. /**
  22. * General Query Method Select operation
  23. * @param sql
  24. * @return Array
  25. */
  26. Public Function QueryRows ($sql) {
  27. Create connection, encode, database
  28. $link = $this->getconn ();
  29. Send SQL
  30. $rs = mysql_query ($sql);
  31. If an error is displayed
  32. if (DEBUG) {
  33. Echo Mysql_error ();
  34. }
  35. $rows = Array ();
  36. while ($row = Mysql_fetch_array ($rs)) {
  37. $rows [] = $row;//pdemo7.php
  38. }
  39. //
  40. Mysql_free_result ($RS);
  41. Mysql_close ($link);
  42. return $rows;
  43. }
  44. /**
  45. * General Query method Select operation query result row data
  46. * @param sql
  47. * @return Array if the failure returns false;
  48. */
  49. Public Function Queryrow ($sql) {
  50. $rs = $this->queryrows ($sql);
  51. if (!empty ($rs [0])) {
  52. return $rs [0];
  53. }
  54. return false;
  55. }
  56. /**
  57. * General Query method Select operation query result one data
  58. * @param sql
  59. * @return Array if the failure returns false;
  60. * Example: SELECT COUNT (*) from user;
  61. */
  62. Public Function Queryobj ($sql) {
  63. $rs = $this->queryrows ($sql);
  64. Var_dump ($RS);
  65. if (!empty ($rs [0][0])) {
  66. return $rs [0][0];
  67. }
  68. return false;
  69. }
  70. Private Function Getconn () {
  71. $link = mysql_connect (' 127.0.0.1 ', ' root ', ');
  72. mysql_query ("Set names UTF8");
  73. mysql_select_db ("News");
  74. return $link;
  75. }
  76. }
Copy Code
MySQL, PHP
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.