

If you are simply inserting the next row in your table (i.e. If you are providing a unique primary key value (as in the example above), it is highly recommended that you select from the table by that column value before attempting an insert. The insertObject method will throw a error if there is a problem inserting the record into the database table. Notice here that we do not need to escape the table name the insertObject method does this for us. $result = JFactory::getDbo()->insertObject('#_user_profiles', $profile) Insert the object into the user profile table.

$profile->profile_value='Inserting a record using insertObject()' The JDatabaseDriver class also provides a convenient method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL. $columns = array('user_id', 'profile_key', 'profile_value', 'ordering') So, we have to add the column name and NULL value to $columns and $values. The column 'profile_value' has empty string '' as default value but we can also store NULL value. $columns = array('user_id', 'profile_key', 'ordering') $columns = array('user_id', 'profile_key', 'profile_value', 'ordering') The database engine will store NULL as value for column 'profile_value'. The column 'profile_value' has NULL as default value. To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method: Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code. Joomla's database querying has changed since the new Joomla Framework was introduced query chaining is now the recommended method for building database queries (although string queries are still supported). Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.
#DECKED BUILDER UPDATE DATABASE CODE#
Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. In addition to these functions, the class automatically creates the database connection. Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. New versions of the Joomla Platform API provide additional functionality which extends the database layer further and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding. Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers.
#DECKED BUILDER UPDATE DATABASE HOW TO#
3.2.1 How to Store Empty Value as NULL When Inserting an Object.
