In this tutorial we will see how to connect with mysqli database and some row queries in CI.
db_connect() – Use to simply connect with mysqli database which is defined in .env file or database.php file. Define this connection as variable $db and use other methods further on it.
Check this official documents for more reference:
$db->query(‘select * from users) – query method to write a raw query on db.
getResult() – To fetch all records as obj
getResult(‘array’) – To fetch all records as array
getRow() – To fetch single row as obj
getRowArray() – To fetch single row as array
getLastQuery() – Return the last query run
getFieldCount() – Return number of fields in table
getFieldNames() – Return array of table fields
getNumRows() – Return number of rows affected by query