• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to a member function row() on boolean

#1
Hi. I am new to codeigniter and I need help with an existing application I'm working on.  We changed the database that runs in ms sql. We created a beta that runs in the same server as the production. I tested the connection in my local unit, and connection runs no issue. But when I deployed it on Beta, it seems i can't run queries. I would get Fatal error: Call to a member function row() on boolean. I am able to display all tables in my database but can't seem to run a query. This table is existing in the database and has a content as well. Any help is very much appreciated.
Sample code below:
Code:
foreach ($tables as $table)
{
 echo "<br>".$table;

 if($table=="tblContents")
 {
     $query = $this->db->get("tblContents");

     foreach ($query->result() as $row)
     {
      echo "<br/>";
      echo "Name: ".$row->name;
      echo " Path: ".$row->path;
     }

 }
}
Reply

#2
I do not see any calls to db->row() in your code, so I suspect the code you're showing is not the trouble spot. That said, the error message "Call to a member function [some_query_builder_method()] on boolean" is an indication that db->get() or db->get_where() has failed and returned FALSE. If those methods succeed they return a CI_DB_result object.

You can, and probably should, always check that you got something usable before proceeding.

PHP Code:
$query $this->db->get("tblContents");
if(
$query)
{
    foreach ($query->result() as $row)
    {
         echo "<br/>";
         echo "Name: ".$row->name;
         echo " Path: ".$row->path;
    }
}
else
{
   //respond to the failed query, i.e. throw an exception or something

Reply

#3
@ dave friend

seems like your suggestion didn't work... to make it worse echo are not manifesting in the browser for the variable values.


anyways this is my issue below

An uncaught Exception was encountered
Type: Error

Message: Call to a member function row() on boolean

Filename: /home/tauenjic/code.tauenji.com/install/application/models/Login_model.php

and this is my code:

<?php

class login_model extends CI_Model
{
function cek_login($where)
{

$this->db->order_by('user_name', 'DESC');
print_r($this->db->get_where('admin', $where)->row());
$query=$this->db->get_where('admin', $where)->row_array();

$data = array();
if($query !== FALSE && $query->num_rows() > 0){
foreach ($query->result_array() as $row) {
$data[] = $row->row_array();
}
}

return $data;

}
}

anywayz hope someone out there is able to help me solve this issue for real
Reply

#4
Did you try using:

PHP Code:
$this->db->reset_query() 

Between the two queries?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
yes tried that reset_query() between the queries and in every other possible line. but the Uncaught exception error keeps obssessing over the "row_array()" or even "result_array()":

An uncaught Exception was encountered
Type: Error

Message: Call to a member function row_array() on boolean

Filename: /home/tauenjic/code.tauenji.com/install/application/models/Login_model.php

Line Number: 9

Backtrace:

File: /home/tauenjic/code.tauenji.com/install/application/controllers/Login.php
Line: 101
Function: cek_login

File: /home/tauenjic/code.tauenji.com/install/index.php
Line: 326
Function: require_once

For some reason its reacting to the row_array()
$query=$this->db->get_where('admin', $where)->row_array();
Reply

#6
You already assigned $query an row_array then you are reassigning it with
an result_array.

Try this and see if it works, not tested.

PHP Code:
// change this
foreach ($query->result_array() as $row) {
$data[] = $row->row_array();

// to this
foreach ($query->row_array() as $row) { 
$data[] = $row
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
well, still not fetching anything from the database sir... and the echo prints aren't showing any values

$this->db->order_by('user_name', 'DESC');
$query=$this->db->get_where('admin', $where);

$data = array();

if($query !== FALSE && $query->num_rows() > 0){
foreach ($query->row_array() as $row) {
$data[] = $row;
print_r("testing");
print_r($data[num_rows()]);
echo ("testing");
$data[] = $row->row_array();
}
}

return $data;


----------------------------------------------------------------------------------------------
THIS IS A SMALL ALGORITHM TESTING IF THERE IS CONNECTIVITY TO THE DATABASE THUS PROVING THERE IS NO ISSUE WITH DATABASE CONNECTIVITY:

//CHECKING DATABASE CONNECTIVITY
$servername = "localhost";
$database = "tauenjic_igni811";
$username = "tauenjic_igni811";
$password = "uh.pS509(7";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Database has Connected successfully so means connectivity is not the problem";
//CHECKING DATABASE CONNECTIVITY
--------------------------------------------------------------------------------------------------------------
Reply

#8
You can use this helper to show a formatted var_dump of the array's

It sounds like your not getting the data from the database.

PHP Code:
<?php

// -----------------------------------------------------------------------

/**
 * varDebug () - Add this method to a CodeIgniter Helper.
 * I named mine - debug_helper.php
 * -----------------------------------------------------------------------
 *
 * Formatted output of var_dump() etc;
 */
if ( ! function_exists('varDebug'))
{
    
/**
     * Debug Helper
     * -------------------------------------------------------------------
     * Outputs the given variable(s) with color formatting and location
     *
     * @param    mixed    - variables to be output
     */
    
function varDebug()
    {
        list(
$callee) = debug_backtrace();

        
$arguments func_get_args();

        
$total_arguments func_num_args();

        echo 
'<div><fieldset style="background: #fefefe !important; border:1px red solid; padding:15px">';
        echo 
'<legend style="background:lightgrey; padding:5px;">'.$callee['file'].' @line: '.
        
     $callee['line'].'</legend><pre><code>';

        
$i 0;
        foreach (
$arguments as $argument) {
            echo 
'<strong>Debug #'.++$i.' of '.$total_arguments.'</strong>: '.'<br>';
            
var_dump($argument);
        }

        echo 
"</code></pre></fieldset><div><br>";

        exit;
    }
}

/**
 * -----------------------------------------------------------------------
 * Filename: debug_helper.php
 * Location: ./app/Helpers/debug_helper.php
 * -----------------------------------------------------------------------
 */ 

Use the helper to check your array's to see if your getting the data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.