0

Hello,
mysq_query($query) returns a valid result set. However,

function query($query)
{
  return mysql_query($query);
}

returns a 1. Why does this happen? Is there a way around it? Thanks in advance.

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by ryy705
0

when mysql_query() executes ok it returns with a 1. try setting the mysql_query() to a variable and then returning the variable itself.

function query($sql) {
  $query = mysql_query($sql);
  return $query;
}

works for me that way.

0

Umm.. No.. mysql_query returns different values for different queries. I just tested and I found out, for a query which doesn't return any resultset, like, update or delete,returns just true. But for a select query, it returns a result (resource id).

0

nav33n is right it. for some reason I kept thinking that it returned 1 showing it executed ok.(looked at php.net) it just returns a resoure id like he said.

my code should work anyway though.

0
<?php
include('connection.php');
$query = "select field from table where field='f1'";
echo mysql_query($query);
echo query($query);
?>

This code returns resouce id #7 for the first command and 1 for the second command. I can't figure out why. there must me a way to pass sql set.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.