{"id":212,"date":"2022-01-12T11:01:50","date_gmt":"2022-01-12T14:01:50","guid":{"rendered":"http:\/\/humanizati.com.br\/blog\/?p=212"},"modified":"2022-01-12T11:03:23","modified_gmt":"2022-01-12T14:03:23","slug":"biblioteca-peardatabase-exemplo-de-uso-vtiger","status":"publish","type":"post","link":"https:\/\/humanizati.com.br\/blog\/2022\/01\/12\/biblioteca-peardatabase-exemplo-de-uso-vtiger\/","title":{"rendered":"Biblioteca PearDatabase &#8211; Exemplo de uso Vtiger"},"content":{"rendered":"\n<p>$adb = PearDatabase::getInstance();<\/p>\n\n\n\n<p>Exemplo de c\u00f3digo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$result = $adb->query('SELECT * FROM vtiger_leadstatus');\n \nwhile($row = $adb->fetchByAssoc($result)){\n $pick_val = $row&#91;$fieldName];\n}\n \n$resultUsers = $adb->query('SELECT id FROM vtiger_users;');\n \nwhile ($userID = $adb->getSingleValue($resultUsers)) {\n echo $userID;\n}\n \n$resultUsers = $adb->query('SELECT id FROM vtiger_users;');\n$userID = $adb->getSingleValue($resultUsers);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Lista de fun\u00e7\u00f5es<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>bind<\/strong>($param, $value, $type = null) &#8211; adds parameters to a query&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.bindvalue.php\">http:\/\/php.net\/manual\/en\/pdostatement.bindvalue.php<\/a>;<\/li><li><strong>checkError<\/strong>($message, $dieOn-Error = false) &#8211; logs errors;<\/li><li><strong>columnMeta<\/strong>(&amp;$result, $col) &#8211; information about a column in results;<\/li><li><strong>completeTransaction()<\/strong>&nbsp;&#8211; transaction completed successfully;<\/li><li><strong>concat<\/strong>($list) &#8211; creates concat value for mysql from an arry;<\/li><li><strong>connect()<\/strong>&nbsp;&#8211; connects to the database;<\/li><li><strong>delete<\/strong>($table, $where = &#8221;, $params = []) &#8211; deletes data;<\/li><li><strong>disconnect()<\/strong>&nbsp;&#8211; disconnects the database;<\/li><li><strong>ErrorMsg()<\/strong>&nbsp;&#8211; error massage for a query&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.errorinfo.php\">http:\/\/php.net\/manual\/en\/pdostatement.errorinfo.php<\/a>;<\/li><li><strong>execute<\/strong>&nbsp;&#8211; executes a query &nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.execute.php\">http:\/\/php.net\/manual\/en\/pdostatement.execute.php<\/a>;<\/li><li><strong>fetch_array<\/strong>($result) &#8211; returns an associative array with all results&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.fetch.php\">http:\/\/php.net\/manual\/en\/pdostatement.fetch.php<\/a>;<\/li><li><strong>fetchByAssoc<\/strong>(&amp;$result, $rowNum = -1, $encode = true) &#8211; returns an associative array, first line by default or a line with a particular number;<\/li><li><strong>flatten_array<\/strong>($input, $output = null) &#8211; flattens a multilevel array to one level;<\/li><li><strong>formatDate<\/strong>($datetime, $strip_quotes = false) &#8211; not supported at the moment;<\/li><li><strong>generateQuestionMarks<\/strong>($items) &#8211; creates a string with&nbsp;&#8220;?&#8221; and there are as many question marks as array elements, e.g. &#8220;?,?,?,?&#8221;;<\/li><li><strong>getAffectedRowCount<\/strong>($result) &#8211; the amount of data for which a query was executed, for selects it&#8217;s the number of records and for updates it&#8217;s the amount of updated data&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.rowcount.php\">http:\/\/php.net\/manual\/en\/pdostatement.rowcount.php<\/a>;<\/li><li><strong>getColumnNames<\/strong>($tablename) &#8211; an array with column names;<\/li><li><strong>getColumnsMeta<\/strong>($tablename) &#8211; an array with objects that contain detailed information about columns in an array;<\/li><li><strong>getEmptyBlob<\/strong>() &#8211; a null sign;<\/li><li><strong>getFieldsArray<\/strong>($result)- an array with columns from results&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.getcolumnmeta.php\">http:\/\/php.net\/manual\/en\/pdostatement.getcolumnmeta.php<\/a>;<\/li><li><strong>getFieldsDefinition<\/strong>($result) &#8211; an array with objects that contain detailed information about columns in an array;<\/li><li><strong>getInstance<\/strong>() &#8211; creates a new PearDatabase instance;<\/li><li><strong>getLastInsertID<\/strong>($seqname = &#8221;) &#8211; id of the last insert&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdo.lastinsertid.php\">http:\/\/php.net\/manual\/en\/pdo.lastinsertid.php<\/a>;<\/li><li><strong>getOne<\/strong>($sql, $dieOn-Error = false, $msg = &#8221;) &#8211; downloads single value from results;<\/li><li><strong>getRowCount<\/strong>($result) &#8211; the number of records;<\/li><li><strong>getSingleValue<\/strong>&nbsp;&#8211; downloads single value from results;&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.fetchcolumn.php\">http:\/\/php.net\/manual\/en\/pdostatement.fetchcolumn.php<\/a>;<\/li><li><strong>getUniqueID<\/strong>($seqname) &#8211; downloads a subsequent ID for an array;<\/li><li><strong>hasFailedTransaction<\/strong>() &#8211; is there an error in transaction?;<\/li><li><strong>insert<\/strong>($table, $data) &#8211; adds data to the database (data &#8211; associative array);<\/li><li><strong>isMySQL<\/strong>() &#8211; is it MySQL database?;<\/li><li><strong>isOracle<\/strong>() &#8211; is it&nbsp;Oracle database?;<\/li><li><strong>isPostgres<\/strong>() &#8211; is it&nbsp;Postgres database?;<\/li><li><strong>log<\/strong>($message, $type = &#8216;info&#8217;) &#8211; saves database logs;<\/li><li><strong>logSqlTime<\/strong>($startat, $endat, $sql, $params = false) &#8211; an advanced save of database logs (under development);<\/li><li><strong>num_fields<\/strong>($result) &#8211; the number of columns in results&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdostatement.columncount.php\">http:\/\/php.net\/manual\/en\/pdostatement.columncount.php<\/a>;<\/li><li><strong>num_rows<\/strong>($result) &#8211; the number of lines in results;<\/li><li><strong>pquery<\/strong>($query, $params = [], $dieOn-Error = false, $msg = &#8221;) &#8211; executes a query with parameters;<\/li><li><strong>prepare<\/strong>($query) &#8211; executes a query&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdo.prepare.php\">http:\/\/php.net\/manual\/en\/pdo.prepare.php<\/a>;<\/li><li><strong>println<\/strong>($msg) &#8211; saves database logs;<\/li><li><strong>query<\/strong>($query, $dieOn-Error = false, $msg = &#8221;) &#8211; executes a query without parameters&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdo.query.php\">http:\/\/php.net\/manual\/en\/pdo.query.php<\/a>;<\/li><li><strong>query_result<\/strong>(&amp;$result, $row, $col = 0) &#8211; downloads data;<\/li><li><strong>query_result_raw<\/strong>(&amp;$result, $row = 0) &#8211; downloads data;<\/li><li><strong>query_result_rowdata<\/strong>($result, $row = 0) &#8211; downloads data;<\/li><li><strong>raw_query_result_rowdata<\/strong>(&amp;$result, $row = 0) &#8211; downloads data;<\/li><li><strong>quote<\/strong>($input, $quote = true, $type = null) &#8211; protects value in sql query &nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdo.quote.php\">http:\/\/php.net\/manual\/en\/pdo.quote.php<\/a>;<\/li><li><strong>requirePsSingleResult<\/strong>($sql, $params, $dieOn-Error = false, $msg = &#8221;, $encode = true) &#8211; number of lines in results has to be equal to 1, otherwise it returns false; an option with parameters;<\/li><li><strong>requireSingleResult<\/strong>($sql, $dieOn-Error = false, $msg = &#8221;, $encode = true) &#8211;&nbsp;number of lines in results has to be equal to 1, otherwise it returns false; an option without parameters;<\/li><li><strong>resetSettings<\/strong>($dbtype, $host, $dbname, $username, $passwd) &#8211; changes data to connect to the database, performing connect() is required afterwards<\/li><li><strong>rollbackTransaction<\/strong>() &#8211; reverse changes performed in a transaction;<\/li><li><strong>setAttribute<\/strong>(func_get_args()) &#8211; sets attributes for a database connection&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/pdo.setattribute.php\">http:\/\/php.net\/manual\/en\/pdo.setattribute.php<\/a>;<\/li><li><strong>setDatabaseHost<\/strong>($host) &#8211; saves host name;<\/li><li><strong>setDatabaseName<\/strong>($dbname) &#8211; save database name;<\/li><li><strong>setDatabaseType<\/strong>($type) &#8211; saves connection;<\/li><li><strong>setDieOnError<\/strong>($bool) &#8211; sets whether a script should be stopped when an error appears;<\/li><li><strong>setUserName<\/strong>($name) &#8211; saves host name;<\/li><li><strong>setUserPassword<\/strong>($pass) &#8211; saves host name;<\/li><li><strong>sql_escape_string<\/strong>($str) -protects values in sql query;<\/li><li><strong>sqlExprDatalist<\/strong>($array) &#8211; creates a string (&#8217;44&#8217;,&#8217;66&#8217;,&#8217;777&#8242;) from a array with protected values;<\/li><li><strong>startTransaction<\/strong>() &#8211; ends transaction;<\/li><li><strong>updateBlob<\/strong>($table, $column, $val, $where) &#8211; updates data.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>$adb = PearDatabase::getInstance(); Exemplo de c\u00f3digo: Lista de fun\u00e7\u00f5es bind($param, $value, $type = null) &#8211; adds parameters to a query&nbsp;http:\/\/php.net\/manual\/en\/pdostatement.bindvalue.php; checkError($message, $dieOn-Error = false) &#8211;&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":2,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/posts\/212\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/humanizati.com.br\/blog\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}