Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated MySQL functions to support last_insert_id().

  • Loading branch information...
commit 82a87bb990c673ce034dcf3913267831845c4b44 1 parent 5e61cc7
@neogeek authored
Showing with 9 additions and 7 deletions.
  1. +2 −2 README.md
  2. +7 −5 framework.php
View
4 README.md
@@ -63,7 +63,7 @@ array getcsv(string $string);
getcsv('data.csv');
##mysql_fetch_results
-Returns the results of a MySQL query as an array or the number of rows affected.
+Returns the results of a MySQL query as an array, the number of rows affected, or the row ID inserted.
###Method
@@ -78,7 +78,7 @@ array|integer mysql_fetch_results(string|resource $query [, array $results]);
mysql_fetch_results('UPDATE `user` SET `date` = NOW()');
##mysqli_fetch_results
-Returns the results of a MySQLi query as an array or the number of rows affected.
+Returns the results of a MySQLi query as an array, the number of rows affected, or the row ID inserted.
###Method
View
12 framework.php
@@ -158,7 +158,7 @@ function getcsv($string) {
/**
* mysql_fetch_results
- * Returns the results of a MySQL query as an array or the number of rows affected.
+ * Returns the results of a MySQL query as an array, the number of rows affected, or the row ID inserted.
* @method array|integer mysql_fetch_results(string|resource $query [, array $results]);
* @param string|resource $query
* @param array $results (optional)
@@ -175,7 +175,7 @@ function mysql_fetch_results($query, $results = array()) {
if (is_resource($query)) { $result = $query; } else { $result = mysql_query($query); }
if (is_resource($result)) {
while ($row = mysql_fetch_assoc($result)) { array_push($results, $row); }
- } else { $results = mysql_affected_rows(); }
+ } else { $results = ($insert_id = mysql_insert_id()) ? $insert_id : mysql_affected_rows(); }
return $results;
}
@@ -183,7 +183,7 @@ function mysql_fetch_results($query, $results = array()) {
/**
* mysqli_fetch_results
- * Returns the results of a MySQLi query as an array or the number of rows affected.
+ * Returns the results of a MySQLi query as an array, the number of rows affected, or the row ID inserted.
* @method array|integer mysqli_fetch_results(resource $resource, string|resource $query [, array $results]);
* @param resource $resource
* @param string|resource $query
@@ -202,7 +202,7 @@ function mysqli_fetch_results($resource, $query, $results = array()) {
if (is_object($result)) {
while ($row = $result->fetch_assoc()) { array_push($results, $row); }
$result->close();
- } else { $results = mysqli_affected_rows($resource); }
+ } else { $results = ($insert_id = mysqli_insert_id($resource)) ? $insert_id : mysqli_affected_rows($resource); }
return $results;
}
@@ -241,7 +241,9 @@ function mysqli_transaction($resource, $query, $types = '') {
$result->execute();
- if (!$meta = $result->result_metadata()) { return $result->affected_rows; }
+ if (!$meta = $result->result_metadata()) {
+ return ($insert_id = $result->insert_id) ? $insert_id : $result->affected_rows;
+ }
while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; }
Please sign in to comment.
Something went wrong with that request. Please try again.