Welcome Guest, Not a member yet? Register   Sign In
A PHP Error was encountered
#1

[eluser]jiahui[/eluser]
Hello, all experts.

What my problem is absolutely same with this article http://ellislab.com/forums/viewthread/45460/#580204 described

But, have tried with use the suggestions of that article what I found there, but my problem is still there.

This is the error message always appearing at the bottom of my web page.
Quote:A PHP Error was encountered
Severity: Warning

Message: Unknown: 2 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query()

Filename: Unknown

Line Number: 0


Any kindness expert willing to guide me drive to the right path?

Following is my source code:

1. In Model :
Code:
<?php
class usercontacts_model extends Model {

    function get_admin_contacts()
    {
        $this->db->where('banned = 0');
        $this->db->orderby('lastname', 'asc');

        return $this->db->get('user');
    }
}
?>

2. In Controller :
Code:
function index()
    {
    $data['accounts'] = $this->usercontacts_model->get_admin_contacts();
}

3. views :

Code:
<?php foreach($accounts->result() as $user):?>
                        <tr>
                            <td>&lt;?php echo $user->firstname.' '.$user->lastname; ?&gt;</td>
                            <td>&lt;?php echo $user->email; ?&gt;</td>
                            <td>&lt;?php echo $user->phone; ?&gt;</td>
                            <td>&lt;?php if ($user->groupid==1) { ?&gt;
                                <img src="&lt;?php echo base_url();?&gt;images/admin.png" border="0" alt="Admin"/>
                                &lt;?php } else if ($user->groupid==2) { ?&gt;
                                <img src="&lt;?php echo base_url();?&gt;images/exporter.png" border="0" alt="Exporter"/>
                                &lt;?php } else if ($user->groupid==3) { ?&gt;
                                <img src="&lt;?php echo base_url();?&gt;images/importer.png" border="0" alt="Importer"/>
                                &lt;?php } ?&gt;&nbsp;
                                &lt;?php if ($user->groupid==1) { ?&gt;
                                Administrator
                                &lt;?php } else if ($user->groupid==2) { ?&gt;
                                Exporter
                                &lt;?php } else if ($user->groupid==3) { ?&gt;
                                Importer
                                &lt;?php } ?&gt;</td>
                            <td>&lt;?php echo $user->ip_address; ?&gt;</td>
                            <td>&lt;?php echo $user->last_login; ?&gt;</td>
                            <td align="center">
                            &lt;?php if ($this->session->userdata('groupid')==1){ ?&gt;
                                    &lt;?php echo ' ['.anchor('accounts/delete/'.$user->id, $this->lang->line('actions_delete'),array('class' => 'delete', 'title'=>$user->firstname)).']';?&gt;
                                    <a >id; ?&gt;"><img src="&lt;?php echo base_url(); ?&gt;images/edit.png" border="0"/></a>
                            &lt;?php }else if ($this->session->userdata('user_id')== $user->id) { ?&gt;
                                    <a >id; ?&gt;"><img src="&lt;?php echo base_url(); ?&gt;images/edit.png" border="0"/></a>
                            &lt;?php } ?&gt;
                            </td>
                        </tr>
                        &lt;?php endforeach;?&gt;
#2

[eluser]jiahui[/eluser]
Was my question not clear? None feedback?
#3

[eluser]John_Betong[/eluser]
[quote author="jiahui" date="1258619670"]Was my question not clear? None feedback?[/quote]
&nbsp;
http://ellislab.com/forums/viewthread/130302/#653952

Try:
1. download the above function and save it to a file
2. require the function in your index.php

Temporarily change these lines of code
Code:
// return $this->db->get('user');
  $query =  $this->db->get('user');
  fred($query->result());
  die;
&nbsp;
Once you know the results, move on to your next lines of code.
&nbsp;
&nbsp;
edit: spelling Sad
#4

[eluser]jiahui[/eluser]
I saved the file in views folder. And require the file in my index.php , also changed my query to :
Code:
$query =  $this->db->get('user');
          fred($query->result());
          die;

But what I get is
Quote:Fatal error: Call to undefined function fred() in C:\inetpub\sgcarmart\hoorfatt\system\application\models\usercontacts_model.php on line 11

Any comments?

Thank you
#5

[eluser]John_Betong[/eluser]
[quote author="jiahui" date="1258633508"]I saved the file in views folder. And require the file in my index.php , also changed my query to :
Code:
$query =  $this->db->get('user');
          fred($query->result());
          die;

But what I get is
Quote:Fatal error: Call to undefined function fred() in C:\inetpub\sgcarmart\hoorfatt\system\application\models\usercontacts_model.php on line 11

Any comments?

Thank you[/quote]
&nbsp;
Save the function in a file called _fred.php in the same directory as your index.php.

In your index,php include the file by using require('_fred.php');

If there is any problem with the _fred.php file then your index.php will show an error and stop processing. Including the file shows any errors but continues processing.

Once _fred.php is being called correctly the fiunction fred($whatever_variable_you_choose); is then available everywhere in your program.

Try it again and let us know the results.
&nbsp;
&nbsp;
&nbsp;
#6

[eluser]jiahui[/eluser]
This is the result list I got:

Code:
Name   ==> [b]missing_$data_name[/b]
Type   ==> array(10)
Count  ==> 10
Value  ==>

Array
(
    [0] => stdClass Object
        (
            [id] => 12
            [username] => ddd.ddddddd
            [password] => UGNSPwEzBzdSZQ1pBWVTPQ==
            [ip_address] => ::1
            [groupid] => 3
            [firstname] => ddd
            [lastname] => dddddd
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [1] => stdClass Object
        (
            [id] => 8
            [username] => ee.eeee
            [password] => eeeeeeee
            [ip_address] => ::1
            [groupid] => 1
            [firstname] => ee
            [lastname] => ee
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [2] => stdClass Object
        (
            [id] => 15
            [username] => jiahui.jiahui
            [password] => BzoDYww7CjZUcgdu
            [ip_address] => ::1
            [groupid] => 3
            [firstname] => jiahui
            [lastname] => jiahui
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [3] => stdClass Object
        (
            [id] => 16
            [username] => law.keng boon
            [password] => CmwBOlE0BGRTNQQy
            [ip_address] => ::1
            [groupid] => 2
            [firstname] => law
            [lastname] => keng boon
            [email] => [email protected]
            [phone] =>
            [last_login] => 2009-11-17 11:09:47
            [banned] => 0
        )

    [4] => stdClass Object
        (
            [id] => 10
            [username] => dd.qqq
            [password] => 12121212
            [ip_address] => ::1
            [groupid] => 2
            [firstname] => dd
            [lastname] => qq
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [5] => stdClass Object
        (
            [id] => 1
            [username] => jiahui
            [password] => C20JMlYzBWUBZwcxXm0KOA==
            [ip_address] => ::1
            [groupid] => 1
            [firstname] => huggie puppy
            [lastname] => Standford
            [email] => [email protected]
            [phone] =>
            [last_login] => 2009-11-20 10:16:58
            [banned] => 0
        )

    [6] => stdClass Object
        (
            [id] => 11
            [username] => 666666
            [password] => 66666
            [ip_address] => ::1
            [groupid] => 2
            [firstname] => testing
            [lastname] => tr
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [7] => stdClass Object
        (
            [id] => 9
            [username] => rtr.trttr
            [password] => rrrrrrr
            [ip_address] => ::1
            [groupid] => 2
            [firstname] => rtr
            [lastname] => trt
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [8] => stdClass Object
        (
            [id] => 13
            [username] => ddd
            [password] => BWYINQNhBWUBZlBkBDQFOwQw
            [ip_address] => ::1
            [groupid] => 3
            [firstname] => erttrty
            [lastname] => tt
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [9] => stdClass Object
        (
            [id] => 7
            [username] => xx.xxxx
            [password] => xxxxxxxx
            [ip_address] => ::1
            [groupid] => 3
            [firstname] => xx
            [lastname] => xx
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

)

Could tell me what is the indeed problem caused this error msg appearing all the times?
Code:
A PHP Error was encountered

Severity: Warning

Message: Unknown: 2 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query()

Filename: Unknown

Line Number: 0
#7

[eluser]John_Betong[/eluser]
[quote author="jiahui" date="1258705983"]This is the result list I got:

Code:
Name   ==> [b]missing_$data_name[/b]
Type   ==> array(10)
Count  ==> 10
Value  ==>

Array
(
    [0] => stdClass Object
        (
            [id] => 12
            [username] => ddd.ddddddd
            [password] => UGNSPwEzBzdSZQ1pBWVTPQ==
            [ip_address] => ::1
            [groupid] => 3
            [firstname] => ddd
            [lastname] => dddddd
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )

    [1] => stdClass Object
        (
            [id] => 8
            [username] => ee.eeee
            [password] => eeeeeeee
            [ip_address] => ::1
            [groupid] => 1
            [firstname] => ee
            [lastname] => ee
            [email] => [email protected]
            [phone] =>
            [last_login] => 0000-00-00 00:00:00
            [banned] => 0
        )
...
...
)

Could tell me what is the indeed problem caused this error msg appearing all the times?
Code:
A PHP Error was encountered

Severity: Warning

Message: Unknown: 2 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query()

Filename: Unknown

Line Number: 0
[/quote]
&nbsp;
Please note that the error message returned is not an error it is a warning. You could hide the warning by changing the error level setting.

I would be tempted to exactly pinpoint where the message is appearing and then take steps to free the result set by using $result->free_result();.

Normally the result set is freed automatically but it appears to be some sort of conflict. To eliminate this I would free the result set every time immediately after I have stored the result set.
&nbsp;
&nbsp;
&nbsp;
#8

[eluser]jiahui[/eluser]
How to do that?

Because I intend to set it like this
Code:
&lt;?php foreach($accounts->free_result() as $user):?&gt;
or
Code:
&lt;?php foreachmy sql_free_result(accounts->result() as $user)):?&gt;
but cannot work.

Could teach me whether got another efficient way to block this msg in front of user?
#9

[eluser]John_Betong[/eluser]
[quote author="jiahui" date="1258710546"]How to do that?

Because I intend to set it like this
Code:
&lt;?php foreach($accounts->free_result() as $user):?&gt;
or
Code:
&lt;?php foreachmy sql_free_result(accounts->result() as $user)):?&gt;
but cannot work.

Could teach me whether got another efficient way to block this msg in front of user?[/quote]
&nbsp;
Try this:
Code:
function get_admin_contacts()
    {

        $this->db->where('banned = 0');
        $this->db->orderby('lastname', 'asc');

        $result = $this->db->get('user');
        $this->db->free_result();

        return $result;

    }
}
&nbsp;
&nbsp;
&nbsp;
#10

[eluser]jiahui[/eluser]
Thank you for your patient.

I tried but got this error msg :

Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::free_result() in C:\inetpub\sgcarmart\hoorfatt\system\application\models\usercontacts_model.php on line 10




Theme © iAndrew 2016 - Forum software by © MyBB