Commit a5fcb369 authored by Dries's avatar Dries
Browse files

- Patch #166205 by hswong3i: improved database compatibility of db_result(). ...

- Patch #166205 by hswong3i: improved database compatibility of db_result().  Makes it work with DB2, Oracle, etc.
parent 15c68075
......@@ -212,14 +212,15 @@ function db_num_rows($result) {
*
* @param $result
* A database query result resource, as returned from db_query().
* @param $row
* The index of the row whose result is needed.
* @return
* The resulting field or FALSE.
*/
function db_result($result, $row = 0) {
if ($result && mysql_num_rows($result) > $row) {
return mysql_result($result, $row);
function db_result($result) {
if ($result && mysql_num_rows($result) > 0) {
// The mysql_fetch_row function has an optional second parameter $row
// but that can't be used for compatibility with Oracle, DB2, etc.
$array = mysql_fetch_row($result);
return $array[0];
}
return FALSE;
}
......
......@@ -211,14 +211,14 @@ function db_num_rows($result) {
*
* @param $result
* A database query result resource, as returned from db_query().
* @param $row
* The index of the row whose result is needed.
* @return
* The resulting field or FALSE.
*/
function db_result($result, $row = 0) {
if ($result && mysqli_num_rows($result) > $row) {
$array = mysqli_fetch_array($result, MYSQLI_NUM);
function db_result($result) {
if ($result && mysqli_num_rows($result) > 0) {
// The mysqli_fetch_row function has an optional second parameter $row
// but that can't be used for compatibility with Oracle, DB2, etc.
$array = mysqli_fetch_row($result);
return $array[0];
}
return FALSE;
......
......@@ -229,16 +229,13 @@ function db_num_rows($result) {
*
* @param $result
* A database query result resource, as returned from db_query().
* @param $row
* The index of the row whose result is needed.
* @return
* The resulting field or FALSE.
*/
function db_result($result, $row = 0) {
if ($result && pg_num_rows($result) > $row) {
$res = pg_fetch_row($result, $row);
return $res[0];
function db_result($result) {
if ($result && pg_num_rows($result) > 0) {
$array = pg_fetch_row($result);
return $array[0];
}
return FALSE;
}
......
......@@ -1398,7 +1398,7 @@ function comment_validate($edit) {
if (!$user->uid || isset($edit['is_anonymous'])) {
if (variable_get('comment_anonymous', COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
if ($edit['name']) {
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']), 0);
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
if ($taken != 0) {
form_set_error('name', t('The name you used belongs to a registered user.'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment