/** * SQL Escape $arg or _REQUEST[$param]. * * @tok {esc:} ab'c {:esc} -> ' ab''c ' * @tok {esc:t} 'a"' {:esc} -> ' ''a"'' ' * @tok {esc:a} AND _REQUEST[a] = " x " -> ' x ' * @tok {esc:t} AND _REQUEST[t] = " x " -> 'x' * @tok {esc:}null{:esc} -> NULL * @tok {esc:}NULL{:esc} -> NULL * @param string $param * @param string $arg * @return string */ public function tok_esc($param, $arg) { if (!empty($param) && (isset($_REQUEST[$param]) || array_key_exists($param, $_REQUEST))) { $arg = $_REQUEST[$param]; } if ($param === 't') { $arg = trim($arg); } $res = ''; if (is_null($arg) || $arg === 'null' || $arg === 'NULL') { $res = 'NULL'; } else { $res = "'" . $this->db->esc($arg) . "'"; } return $res; }
/** * Return translation. Select language or default based on getTxtId(). * If Text is not translated return untranslated(). If text has changed * remove translation in database. Text $txt must be static otherwise use tok_ptxt(). * Examples: * * - {txt:}Hallo {get:firstname} {get:lastname}{:txt} -> invalid !! * - {txt:}Hallo{:txt} -> id = md5('Hallo') * - {txt:hi}Hallo{:txt} -> id = hi * - {txt:}=hi{:txt} -> id = hi * * @throws * @see getTxtId * @see untranslated * @see tok_ptxt * @param string $param custom id or empty * @param string $txt default text or empty * @return string */ public function tok_txt($param, $txt) { $id = $this->getTxtId($param, $txt); if (($trans = $this->db->query('select', ['id' => $id], -1)) === false) { // no translation - insert untranslated text and return raw $this->db->query('insert:exec', ['id' => $id, 'txt' => $txt]); return $this->untranslated('txt', $param, $txt); } if ($trans['txt'] !== $txt) { // text has changed: remove translation, insert untranslated text and return raw $this->db->query('delete:exec', ['id' => $id]); $this->db->query('insert:exec', ['id' => $id, 'txt' => $txt]); return $this->untranslated('txt', $param, $txt); } $res = $trans['lang']; if (empty($res)) { $res = empty($trans['default']) ? $this->untranslated('txt', $param, $txt) : $trans['default']; } return $res; }
$id = $db->auto_incr_insert("INSERT INTO aaa (n, name) VALUES ('\$detect_max_n', '$i')", "aaa", "n"); $db->execute("UPDATE aaa SET value='$i' WHERE n='$id'"); } $db->select("SELECT * FROM aaa WHERE name != value"); --> per System Aufruf php aaa.php & php aaa.php & php aaa.php & php aaa.php & */ /** * M A I N */ // create database if necessary ... $db = new \rkphplib\MysqlDatabase(); $db->setDSN($admin_dsn); $dsn_info = \rkphplib\ADatabase::splitDSN($dsn); if (!$db->hasDatabase($dsn_info['name'])) { $db->createDatabase($dsn); } $prof = new \rkphplib\Profiler(); $prof->startXDTrace(); $prof->log('start test'); // \rkphplib\MysqlDatabase::$use_prepared = false; call_test('create', array(), array('MysqlDatabase create/desc', 1, 1, 1, 1)); call_test('insert', array(), array('MysqlDatabase insert', 1, 1, 1, 1)); $prof->log('done.'); $prof->stopXDTrace(); print "\nProfiler Log:\n"; $prof->writeLog(); print "\n\n";
/** * Create category table. Default conf: * * - @table=category * - @id=1 * - pid= int:::32 * - name= varchar:255::1 * * Don't change "@id" and "pid" in conf. For multilanguage use "@language" => 'de, en, ...' and "@multilang" => 'name'. * * @param map $conf * @see ADatabase::createTable() */ public function createTable($conf = ['@table' => 'category', '@id' => 1, 'pid' => 'int:::32', 'name' => 'varchar:255::1']) { $this->db->createTable($conf); }