Source for file MySQLInsertQueryResult.class.php

Documentation is available at MySQLInsertQueryResult.class.php

  1. <?php
  2. /**
  3. * @package harmoni.dbc.mysql
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: MySQLInsertQueryResult.class.php,v 1.6 2007/09/05 21:39:00 adamfranco Exp $
  9. */
  10. require_once(HARMONI."DBHandler/InsertQueryResult.interface.php");
  11.  
  12. /**
  13. * The InsertQueryResult interface provides the functionality common to all INSERT query results.
  14. *
  15. * For example, you can get the primary key for the last insertion, get number of inserted rows, etc.
  16. *
  17. * @package harmoni.dbc.mysql
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: MySQLInsertQueryResult.class.php,v 1.6 2007/09/05 21:39:00 adamfranco Exp $
  23. */
  24.  
  25. class MySQLInsertQueryResult
  26. implements InsertQueryResultInterface
  27. {
  28.  
  29.  
  30. /**
  31. * The link identifier for the database connection.
  32. * The link identifier for the database connection.
  33. * @param integer $_linkId The link identifier for the database connection.
  34. * @access private
  35. */
  36. var $_linkId;
  37. /**
  38. * Gets the last auto increment value that was generated by the INSERT query.
  39. * Gets the last auto increment value that was generated by the INSERT query.
  40. * @access private
  41. * @var integer $_lastAutoIncrementValue The last auto increment value that was generated by the INSERT query.
  42. */
  43. var $_lastAutoIncrementValue;
  44.  
  45. /**
  46. * Stores the number of rows processed by the query.
  47. * Stores the number of rows processed by the query.
  48. * @var integer $_numberOfRows The number of rows processed by the query.
  49. * @access private
  50. */
  51. var $_numberOfRows;
  52.  
  53.  
  54. /**
  55. * Creates a new MySQLINSERTQueryResult object.
  56. * Creates a new MySQLINSERTQueryResult object.
  57. * @access public
  58. * @param integer $linkId The link identifier for the database connection.
  59. * @return object MySQLINSERTQueryResult A new MySQLINSERTQueryResult object.
  60. */
  61. function MySQLInsertQueryResult($linkId) {
  62. // ** parameter validation
  63. $resourceRule = ResourceValidatorRule::getRule();
  64. ArgumentValidator::validate($linkId, $resourceRule, true);
  65. // ** end of parameter validation
  66.  
  67. $this->_linkId = $linkId;
  68. $this->_numberOfRows = mysql_affected_rows($this->_linkId);
  69.  
  70. // in MySQL, when inserting several rows with one INSERT query,
  71. // mysql_insert_id() returns the id of the first row.
  72. // Thus, we need to add the number of inserted rows - 1 to get the actual
  73. // last id.
  74. $this->_lastAutoIncrementValue = mysql_insert_id($this->_linkId) + $this->getNumberOfRows() - 1;
  75. }
  76.  
  77. /**
  78. * Gets the last auto increment value that was generated by the INSERT query.
  79. * Gets the last auto increment value that was generated by the INSERT query.
  80. * @access public
  81. * @return integer The last auto increment value that was generated by the INSERT query.
  82. */
  83. function getLastAutoIncrementValue() {
  84. return $this->_lastAutoIncrementValue;
  85. }
  86.  
  87. /**
  88. * Returns the number of rows that the query processed.
  89. * Returns the number of rows that the query processed. For a SELECT query,
  90. * this would be the total number of rows selected. For a DELETE, UPDATE, or
  91. * INSERT query, this would be the number of rows that were affected.
  92. * @return integer Number of rows that were processed by the query.
  93. * @access public
  94. */
  95. function getNumberOfRows() {
  96. return $this->_numberOfRows;
  97. }
  98.  
  99.  
  100. }
  101.  
  102. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:11 -0400 by phpDocumentor 1.3.0RC3