

Notice that when we execute the query, we're executing it with the cursor as usual. Next, let's create another function, calling it read_from_db: def read_from_db(): Let's see what I mean:Ĭ.execute("CREATE TABLE IF NOT EXISTS stuffToPlot(unix REAL, datestamp TEXT, keyword TEXT, value REAL)")Ĭ.execute("INSERT INTO stuffToPlot VALUES(1452549219,' 13:53:39','Python',6)")ĭate = str((unix).strftime('%Y-%m-%d %H:%M:%S'))Ĭ.execute("INSERT INTO stuffToPlot (unix, datestamp, keyword, value) VALUES (?, ?, ?, ?)", While we can query the entire table, we can instead just query a single column, or even based on specific row values. Reading from a database is where the power of using something like SQLite over a flat file starts to make sense.

#Read db text how to#
DB layer 2.0 migration docs: Information about how to modify your code to work with the new Moodle 2.0 DB layer.In the previous tutorials, we've covered creating a database and populating one, now we need to learn how to read from the database.DB layer 2.0 examples: To see some code examples using various DML functions.DDL functions: Where all the functions used to handle DB objects ( DDL) are defined.DML functions - pre 2.0: (deprecated!) For information valid before Moodle 2.0.
#Read db text drivers#

False boolean is returned if the requested record is not found. IGNORE_MISSING - In this mode, a missing record is not an error.An exception will be thrown if no record is found or multiple matching records are found. MUST_EXIST - In this mode, the requested record must exist and must be unique.Supported modes are specified using the constants: Some methods accept the $strictness parameter affecting the method behaviour. $DB -> get_record_sql ( 'SELECT * FROM WHERE firstname = :firstname AND lastname = :lastname', ) Strictness Example of using question mark placeholders. The DB object is available in the global scope right after including the config.php file:.as a part of including the main config.php file. It is instantiated automatically during the bootstrap setup, i.e. The $DB global object is an instance of the moodle_database class.

