CodeIgniter Query Get Where

I have the following:

/** Load necessary stuff **/

        //echo mdate('%Y-%m-%d %H:%i:%s', now());
        $this->db->where("(created_for <= " . "'2019-04-24 18:47:03'" . ")");

But I receive the following:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (`created_for` <= '2019-04-24 18:47:03')' at line 2

SELECT * WHERE (`created_for` <= '2019-04-24 18:47:03')

Filename: modules/sound/models/Sound_request_model.php

Line Number: 35

What am I doing wrong?

You can put it into one statement

    $this->db->get_where('site_requests', array('created_for <=', '2019-04-24 18:47:03'));

You will need to chain ->result() or result_array() or any outputting function to get the data return.

Hopefully this helps

Query Builder Class — CodeIgniter 4.0.4 documentation, Selecting Data�. The following functions allow you to build SQL SELECT statements. $builder->get(). Runs the selection query and returns the� Codigniter $this->db->get_where () allows you to create a sql slect query having the WHERE Clause. $query = $this->db->get_where ($table_name,$where_array, $limit, $offset); $table_name – Your table name. $where_array – Array which generates the condition.

$this->db->where("(created_for <= " . "'2019-04-24 18:47:03'" . ")");

should be after


Generating Query Results — CodeIgniter 4.0.4 documentation, get your results as an array of arrays: $query = $db->query("YOUR QUERY"); foreach ($query->getResult('array') as $row) { echo $row['title'];� Just for reference, you should usually have you "data" code as a model function, in this case the get_where functionality. I highly suggest you read through the provided User Guide to get to grips with CodeIgniter, it should hold your hand through most steps. See: Table of Contents (top right).

Try using the key-value form:

$this->db->where("created_for <=", "2019-04-24 18:47:03");

query in codeigniter: get where or, You can use the where_in method as a shortcut to multiple or-statements for the same column: $available_ids = [1, 2, 3];� Similarly, Codeigniter has to provide a simple query to replace data from the MySQL database using a clause. This is update query $this->db->replace (); public function update_row(){ $update_rows = array('field-name' => 'field-data',); $this->db->where('id', 1 ); $this->db->update('table-name', $update_rows); }

You are missing defining the FROM part of query. I think you just need to change your code:

    $query = $this->db->from('site_requests')
       ->where("(created_for <= " . "'2019-04-24 18:47:03'" . ")")
    $result = $query->result();

CodeIgniter Select Query | W3Schools | Tutorialspoint, In CodeIgniter, get() method is used to run select statement and return data from table. It can be used stand alone to retrieve all records from a table. Syntax:-. CodeIgniter 'SELECT' query will execute using following functions. They are. $this->db->query () $this->db->query () With Query Bindings. $this->db->get () $this->db->get () Select The Fields. $this->db->get () With Limit. $this->db->get () With Offset,Limit. $this->db->get () With select, from.

CodeIgniter – Select Query, You can get the current prefix any time with this method: use CodeIgniter\ Database\Query; $pQuery = $db->prepare(function($db) { $sql� The query() function returns a database result object when “read” type queries are run, which you can use to show your results. When “write” type queries are run it simply returns TRUE or FALSE depending on success or failure. When retrieving data you will typically assign the query to your own variable, like this:

Queries — CodeIgniter 4.0.4 documentation, We can get last executed query using last_query() function of db class in codeigniter. It is a very simple to use $this->db->last_query() function to� CodeIgniter gives you access to a Query Builder class. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases, only one or two lines of code are necessary to perform a database action. CodeIgniter does not require that each database table be its own class file.

How to get last executed query in PHP Codeigniter?, Here's your complete guide to learn Codeigniter Active Records, that Now in the 'activerecords' database, create a table named 'customer' through the following query: Be the first to get the latest updates and tutorials. It frees the memory associated with the result and deletes the result resource ID. Normally PHP frees its memory automatically at the end of script execution. However, if you are running a lot of queries in a particular script you might want to free the result after each query result has been generated in order to cut down on memory consumption.