Db Connection

I want to write a new php file which will use a new table to write some data but this table will be part of the cs-cart db only.

What are the basic set of lines which I can use to get the Database connection,objects from cs-cart itself rather than writing them separately again?

For example,

define(‘AREA’, ‘C’);
require dirname(FILE) . ‘./init.php’;

Your question is not clear. Is this a PHP file that is part of an addon or part of the initialized site? If not, then you need to start with what Ecom suggested. You could then use the connection info defined in the config.local.php file which is instantiated in the registry as (for instance the db_name) Registry::get('config.db_name').

But you should familiarize yourself with the standard database functions as defined in app/functions/fn.database.php.

The most commonly used are:

db_query() - execute a query for update, insert, delete, table modifications, etc.

db_get_array() - gets an array of data

db_get_row() - gets one row of data

db_get_field() - gets one field from a query

db_get_fields() - gets an array of a single column

db_get_hashed_array() - a hashed array of data with index of a field (I.e. product_id)

There are many others, but these are the most common.

Note that you should also get familiar with the 'shorthand notation' used. I.e.

?: - table prefix

?i - integer value

?d - decimal value

?s - quoted string

?e - array for INSERT/REPLACE

?u - array for UPDATE

Again, there are many others but these are most common.

So something like: db_get_hashed_array("SELECT product_id, product_code FROM ?:products WHERE status=?s", 'product_id', 'A');

Would return an array of data (product_id and product_code) indexed by the product_id for all products with a status of 'A' (active).

Thanks guys for all the inputs.