0

Good morning, I have a problem with mysql and coeigniter 3. if I request data with

$ query = $ this-> db-> query ($ queri_str);

it does not give me results. if I enter the query on phpmyadmin it shows me two results.

$ queri_str = 'SELECT * FROM `my_table` WHERE` id_mytable2` = "'. $ id_name. '"';

The database tables were created with mysql workbench and automatically the reference to the main table with a 1: n ratio was added

2
  • print your last query using codeigniter and check it. Commented Dec 6, 2018 at 9:25
  • my last query is SELECT data FROM ci_sessions WHERE id = '58e5j0m5bqrs7hk8suokko28hj7ni0v6' Commented Dec 6, 2018 at 9:34

3 Answers 3

1

Try this query

$this->db->select('*');
    $this->db->where('id', '58e5j0m5bqrs7hk8suokko28hj7ni0v6');
    $result = $this->db->get('ci_sessions')->result_array();
    print_r($result);
Sign up to request clarification or add additional context in comments.

6 Comments

result print 'Array ( [0] => Array ( [id] => 58e5j0m5bqrs7hk8suokko28hj7ni0v6 [ip_address] => ::1 [timestamp] => 1544088965 [data] => __ci_last_regenerate|i:1544088681;username|s:7:"johndoe";email|s:21:"[email protected]";email1|s:21:"[email protected]";email2|s:21:"[email protected]";logged_in|b:1; ) )
so you got the result.
but the problem is that I'm calling the query from a model does not hit anything with ci_sessions how do I clean up the status of the queries and set up a new one
so can you explain me what you want to do?
previous I used only $ this-> db-> query ($ queri_str); instead using: $ This-> db-> select $ This-> db-> where $ This-> db-> get returns the values ​​of the new quey.
|
1

Try this solution, you want to do a normal select,I don't know the query your wrote but

public fucntion get_data($id){

     $this->db->select('*');
    $this->db->from('your_table');
    $this->db->where('id','=' ,'$id');
    $query = $this->db->get();
     $data = $query->result_array(); 
     return $data;
   }

1 Comment

doing this function the result is empty while if I do it in phpmyadmin it gives me two results
0

the problem is back. I'll explain.

function myfunction($id_myname) {
    $this->db->select('*');
    $this->db->where('id_myname', $id_myname);
    //$query = $this->db->get('my_table');
    $query = $this->db->get('my_table');
    //print_r($query);
    //var_dump($query);
    if ( !$query ){
        $error = $this->db->error(); // Has keys 'code' and 'message'
    }
    return $query->result();
}

when I call this function an empty value comes back to me. While if I enter the value of the query in phpmyadmin I find two values

9 Comments

use the query I sent you.it's much simpler to understand,from your query codeigniter doesn't know whether to return a row or an array.try the code i gave you before you add anything else
function myfunction($id_myname) { $this->db->select('*'); $this->db->where('id_myname', $id_myname); $query = $this->db->get('my_table'); if($query->num_rows() > 0){ $data = $query->row(); return true; } return false; }
public fucntion get_data($id){ $this->db->select('*'); $this->db->from('your_table'); $this->db->where('id','=' ,'$id'); $query = $this->db->get(); $data = $query->result_array(); return $data; } the result is empty,but if write select in phpmyadmin return two result.
are you sure ,you have the db credentials correct is your config file?
let me see where you are calling this function in your controller
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.