php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14086 If you use the result set of a insert query, you get a warning message.
Submitted: 2001-11-16 11:25 UTC Modified: 2001-11-16 13:59 UTC
From: oliver at samera dot com dot py Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.0.4pl1 OS: Linux 2.4
Private report: No CVE-ID: None
 [2001-11-16 11:25 UTC] oliver at samera dot com dot py
If you use the result set of a insert query, you get a warning message.

// connect
// do an insert
$result = mysql_query("insert into table1(col1) values(1)");
// free a result
mysql_free_result($result);
// a warning is generated

Warning: Supplied argument is not a valid MySQL result resource in your_source.php on line line_number

php-mysql-4.0.4pl1-9
mysql-3.23.36-1
RedHat 7.1


'./configure' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--enable-shared' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--with-exec-dir=/usr/bin' '--with-regex=system' '--with-gettext' '--with-gd' '--with-jpeg-dir=/usr' '--with-png' '--with-zlib' '--with-db2' '--with-db3' '--with-gdbm' '--enable-debugger' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-yp' '--enable-ftp' '--enable-wddx' '--without-mysql' '--without-oracle' '--without-oci8' '--with-xml'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-16 11:29 UTC] oliver at samera dot com dot py
Summary changed
 [2001-11-16 11:30 UTC] oliver at samera dot com dot py
Tested in RedHat 7.1 with official updates.
 [2001-11-16 13:11 UTC] derick@php.net
From the manual: (http://uk.php.net/manual/en/function.mysql-query.php):

 mysql_query() returns TRUE (non-zero) or FALSE  to indicate whether or not the query succeeded. A return value of TRUE means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.

<snip>

 For SELECT statements, mysql_query() returns a new result identifier that you can pass to mysql_result(). When you are done with the result set, you can free the resources associated with it by calling mysql_free_result().

Not a bug, but intended behavior >> bogus
 [2001-11-16 13:34 UTC] oliver at samera dot com dot py
But, can I free a result set that returned mysql_query in mysql_result_free?

Does this code works? :
// here I'm successfully conected using mysql_pconnect();
$result = mysql_query("insert into table1(col1) values(1)");
if($result) {
  // here I get a warning only if I used a insert statment
  mysql_free_result($result);
}


 [2001-11-16 13:44 UTC] hholzgra@php.net
please *read* the manual page or at least the snippet from the previous message

mysql_query() will only return a result set on SELECT statements 

in any other case it will just return true or false which do not need to be freed

if you realy want to be sure you can do something like

$res = mysql_query(...);
if($res) {
  if(is_resourece($res)) {
    ... process result set ...
    mysql_free_result($res);
  } else {
    ... just be happy that your statement succeded ..
  }
} else {
  ... error handling ...
}



 [2001-11-16 13:59 UTC] oliver at samera dot com dot py
Sorry about the confusion,
as the manual says, only if you use a SELECT statement you can free the result using mysql_free_result().

My fault.

This really is a bogus bug report. :-)

Thanks for the is_resourece() tip.

Oliver

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 20:01:29 2024 UTC