Viewed   204 times

I have Connected SQL Server 2014 with CodeIgniter. but when I run a query it gives that error.

This is the code which gives an error.

 function index()
  {
    $this->form_validation->set_rules('username', 'Username','required');
    $this->form_validation->set_rules('password', 'Password','required');
    if($this->form_validation->run() == TRUE)
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $this->db->select('*');
        $this->db->from('student');
        $this->db->where(array('student_id'=>$username,'password'=>$password));
        $query = $this->db->get();
        $data = $this->db->result();
        if($data)
        {
          echo "<pre> ";
          print_r($data);
        }
    }
  $this->login('login');
  }
}

The Error is

Fatal error: Call to undefined method CI_DB_sqlsrv_driver::result() in D:XampphtdocsCI_Portalapplicationmodelsmy_model.php on line 14

 Answers

1

Try be changing $this->db->result(); as $query->result();

$this->db->select('*');
$this->db->from('student');
$this->db->where(array('student_id' => $username, 'password' => $password));
$query = $this->db->get();
$data = $query->result();

The result resource is there after you actually get the table results.

Or you can use it as:

$data = $this->db->get()->result();
Thursday, November 3, 2022
 
raman
 
1
function __construct(){   $ingObject = new Ingredient();   }

ought to be

function __construct(){   $this->ingObject = new Ingredient();   }

In the first case you're setting a local variable, not a field, so it remains null. Then on the validateData you invoke a method on a null variable.

I'm assuming you snipped some code, because your Ingredient class doesn't make sense (there's a $validate variable there that isn't defined).

Friday, September 9, 2022
 
4

Hm, understand. As I see the subquery's source code in line 27, it wants to call _compile_select or get_compiled_select. If you can check in CI's DB_active_rec.php the _compile_select is protected so you can't access from Subquery (it isn't subclass of db).

Possible solution: _compile_select() should public or class Subquery should be extend of CI's db class. I think you should report this to author of Subquery.

Or you can extend the CI's db class :)

Sorry - I want to write it as a comment.

Sunday, December 18, 2022
 
ghazi
 
3

Try this code it might help you :

Here dashboard is the name of controller

//this will route as localhost/appFolder/admin/index
  $route['admin'] = 'dashboard'; // for your index page

//this will route as localhost/appFolder/admin/method_name
 $route['admin/(:any)'] = 'dashboard/$1';

//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';

Link the route Like

// for your index page
<a href="<?php echo base_url('admin/index'); ?>"></a>

// for your other pages
<a href="<?php echo base_url('admin/method_name'); ?>"></a>

To link the other controller defined just like

 <a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>
Sunday, September 4, 2022
 
3

You got to use pagination() function without get() or getResult() and note that it is a function from the Model class your custom model extend from. So you should call it directly from the model, not from $this->db (this is why he doesn't know it).

This should be the function in your model :

public function brand_name($brand_name_slug)
    {
        return $this
                    ->table('shop a')
                    ->select()
                    ->join('(SELECT sku, MIN(sale_price) AS sale_price FROM shop GROUP BY sku) AS b', 'a.sku = b.sku AND a.sale_price = b.sale_price')
                    ->where('availability', 'in stock')
                    ->where('a.sku !=', '')
                    ->where('brand_name_slug', $brand_name_slug)
                    ->groupBy('a.sku')
                    ->orderBy('brand_name, subbrand_name, product, size, unit')
                    ->paginate(10);
    }

And $data in your controller :

$data = [
            'category_menu' => $model->category_menu(),
            'brand_menu' => $model->brand_menu(),
            'nav' => $model->nav(),
            'subnav' => $model->subnav(),
            'shop' => $model->brand_name($brand_name_slug),
            'pager' => $model->pager
        ];
Saturday, December 10, 2022
 
njames
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share