[eluser]SPeed_FANat1c[/eluser]
I am using codeigniter for long time and want to create new test project and get an error:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: controllers/welcome.php
Line Number: 42
My code is simple
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
if (isset($_GET)) {
echo json_encode($this->get_all());
}
//$this->load->view('welcome_message');
echo 'test';
}
// will use contacts database to not create aditional
private function get_all() {
$this->load->database();
$sql = "SELECT name as brand, address as color, tel as max_speed FROM contacts";
print_r($this->db);
$this->db->query($sql);
return $query->result_array();
}
}
and when print $this->db here is result
Quote:CI_DB_mysql_driver Object
(
[dbdriver] => mysql
[_escape_char] => `
[_like_escape_str] =>
[_like_escape_chr] =>
[delete_hack] => 1
[_count_string] => SELECT COUNT(*) AS
[_random_keyword] => RAND()
[use_set_names] =>
[ar_select] => Array
(
)
[ar_distinct] =>
[ar_from] => Array
(
)
[ar_join] => Array
(
)
[ar_where] => Array
(
)
[ar_like] => Array
(
)
[ar_groupby] => Array
(
)
[ar_having] => Array
(
)
[ar_keys] => Array
(
)
[ar_limit] =>
[ar_offset] =>
[ar_order] =>
[ar_orderby] => Array
(
)
[ar_set] => Array
(
)
[ar_wherein] => Array
(
)
[ar_aliased_tables] => Array
(
)
[ar_store_array] => Array
(
)
[ar_caching] =>
[ar_cache_exists] => Array
(
)
[ar_cache_select] => Array
(
)
[ar_cache_from] => Array
(
)
[ar_cache_join] => Array
(
)
[ar_cache_where] => Array
(
)
[ar_cache_like] => Array
(
)
[ar_cache_groupby] => Array
(
)
[ar_cache_having] => Array
(
)
[ar_cache_orderby] => Array
(
)
[ar_cache_set] => Array
(
)
[ar_no_escape] => Array
(
)
[ar_cache_no_escape] => Array
(
)
[username] => root
[password] =>
[hostname] => localhost
[database] => backbone_contacts_manager
[dbprefix] =>
[char_set] => utf8
[dbcollat] => utf8_general_ci
[autoinit] => 1
[swap_pre] =>
[port] =>
[pconnect] => 1
[conn_id] => Resource id #28
[result_id] =>
[db_debug] => 1
[benchmark] => 0
[query_count] => 0
[bind_marker] => ?
[save_queries] => 1
[queries] => Array
(
)
[query_times] => Array
(
)
[data_cache] => Array
(
)
[trans_enabled] => 1
[trans_strict] => 1
[_trans_depth] => 0
[_trans_status] => 1
[cache_on] =>
[cachedir] =>
[cache_autodel] =>
[CACHE] =>
[_protect_identifiers] => 1
[_reserved_identifiers] => Array
(
[0] => *
)
[stmt_id] =>
[curs_id] =>
[limit_used] =>
[stricton] =>
)
I don't get at all how this cannot work when it is working evrywhere? I also loeaded database in autoload file.