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.

Recommended Answers

All 4 Replies

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.

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).

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.

<?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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.