Basic Info | Database | Display | Forms | Monju | Session | Users

db_query

db_query($query, $returnType = 'RAW', $queryData = -1)

Description

db_query first ensures that there is a connection to the database, or tries to make one if there isn't. It then will query the database and return the result in a helpful manor. You should use :variables to ensure that no SQL injection occurs.

Parameters

$query: SQL string with which to query the database. [type:array]

$returnType: Default return type is RAW. Allowable types are: 'RAW', 'ASSOC', 'ASSOC_ALL', 'NUM', 'NUM_ALL', 'BOTH', 'BOTH_ALL' and 'COUNT'. [type:string]

$queryData: Array of keys which correspond to query variables. Values of the keys denote the accepted type. [type:array]

Return Values

On Success: MySQL result represented according to $returnType On Failure: False

Notes

db_connect() is optional.

Examples

// set the variables to use in the query $data[':name'] = 'Some User'; // build the query $sql = 'SELECT * FROM table WHERE user = :name AND type = `beginner`'; // execute the query and get the result $result = db_query($sql, 'ASSOC_ALL', $data); // $result is now an associative array of all the results of the query

Dependencies

- Must have properly configured the database settings in monju/modules/configuration.inc.php

Comments

Support the Docs!

If you notice a mistake in the documentation, instead file a bug report in the issue tracker. Instead use this to add tips and tricks associated with the functions. You can use tags like to keep your comments clear.