$adb = PearDatabase::getInstance();
Exemplo de código:
$result = $adb->query('SELECT * FROM vtiger_leadstatus');
while($row = $adb->fetchByAssoc($result)){
$pick_val = $row[$fieldName];
}
$resultUsers = $adb->query('SELECT id FROM vtiger_users;');
while ($userID = $adb->getSingleValue($resultUsers)) {
echo $userID;
}
$resultUsers = $adb->query('SELECT id FROM vtiger_users;');
$userID = $adb->getSingleValue($resultUsers);
Lista de funções
- bind($param, $value, $type = null) – adds parameters to a query http://php.net/manual/en/pdostatement.bindvalue.php;
- checkError($message, $dieOn-Error = false) – logs errors;
- columnMeta(&$result, $col) – information about a column in results;
- completeTransaction() – transaction completed successfully;
- concat($list) – creates concat value for mysql from an arry;
- connect() – connects to the database;
- delete($table, $where = ”, $params = []) – deletes data;
- disconnect() – disconnects the database;
- ErrorMsg() – error massage for a query http://php.net/manual/en/pdostatement.errorinfo.php;
- execute – executes a query http://php.net/manual/en/pdostatement.execute.php;
- fetch_array($result) – returns an associative array with all results http://php.net/manual/en/pdostatement.fetch.php;
- fetchByAssoc(&$result, $rowNum = -1, $encode = true) – returns an associative array, first line by default or a line with a particular number;
- flatten_array($input, $output = null) – flattens a multilevel array to one level;
- formatDate($datetime, $strip_quotes = false) – not supported at the moment;
- generateQuestionMarks($items) – creates a string with “?” and there are as many question marks as array elements, e.g. “?,?,?,?”;
- getAffectedRowCount($result) – the amount of data for which a query was executed, for selects it’s the number of records and for updates it’s the amount of updated data http://php.net/manual/en/pdostatement.rowcount.php;
- getColumnNames($tablename) – an array with column names;
- getColumnsMeta($tablename) – an array with objects that contain detailed information about columns in an array;
- getEmptyBlob() – a null sign;
- getFieldsArray($result)- an array with columns from results http://php.net/manual/en/pdostatement.getcolumnmeta.php;
- getFieldsDefinition($result) – an array with objects that contain detailed information about columns in an array;
- getInstance() – creates a new PearDatabase instance;
- getLastInsertID($seqname = ”) – id of the last insert http://php.net/manual/en/pdo.lastinsertid.php;
- getOne($sql, $dieOn-Error = false, $msg = ”) – downloads single value from results;
- getRowCount($result) – the number of records;
- getSingleValue – downloads single value from results; http://php.net/manual/en/pdostatement.fetchcolumn.php;
- getUniqueID($seqname) – downloads a subsequent ID for an array;
- hasFailedTransaction() – is there an error in transaction?;
- insert($table, $data) – adds data to the database (data – associative array);
- isMySQL() – is it MySQL database?;
- isOracle() – is it Oracle database?;
- isPostgres() – is it Postgres database?;
- log($message, $type = ‘info’) – saves database logs;
- logSqlTime($startat, $endat, $sql, $params = false) – an advanced save of database logs (under development);
- num_fields($result) – the number of columns in results http://php.net/manual/en/pdostatement.columncount.php;
- num_rows($result) – the number of lines in results;
- pquery($query, $params = [], $dieOn-Error = false, $msg = ”) – executes a query with parameters;
- prepare($query) – executes a query http://php.net/manual/en/pdo.prepare.php;
- println($msg) – saves database logs;
- query($query, $dieOn-Error = false, $msg = ”) – executes a query without parameters http://php.net/manual/en/pdo.query.php;
- query_result(&$result, $row, $col = 0) – downloads data;
- query_result_raw(&$result, $row = 0) – downloads data;
- query_result_rowdata($result, $row = 0) – downloads data;
- raw_query_result_rowdata(&$result, $row = 0) – downloads data;
- quote($input, $quote = true, $type = null) – protects value in sql query http://php.net/manual/en/pdo.quote.php;
- requirePsSingleResult($sql, $params, $dieOn-Error = false, $msg = ”, $encode = true) – number of lines in results has to be equal to 1, otherwise it returns false; an option with parameters;
- requireSingleResult($sql, $dieOn-Error = false, $msg = ”, $encode = true) – number of lines in results has to be equal to 1, otherwise it returns false; an option without parameters;
- resetSettings($dbtype, $host, $dbname, $username, $passwd) – changes data to connect to the database, performing connect() is required afterwards
- rollbackTransaction() – reverse changes performed in a transaction;
- setAttribute(func_get_args()) – sets attributes for a database connection http://php.net/manual/en/pdo.setattribute.php;
- setDatabaseHost($host) – saves host name;
- setDatabaseName($dbname) – save database name;
- setDatabaseType($type) – saves connection;
- setDieOnError($bool) – sets whether a script should be stopped when an error appears;
- setUserName($name) – saves host name;
- setUserPassword($pass) – saves host name;
- sql_escape_string($str) -protects values in sql query;
- sqlExprDatalist($array) – creates a string (’44’,’66’,’777′) from a array with protected values;
- startTransaction() – ends transaction;
- updateBlob($table, $column, $val, $where) – updates data.