/** * 插入更新数据 * @param string $sql 需要执行的sql语句 * @return int */ public function execute($sql) { $count = $this->pdo->exec($sql); if ($count && false !== strpos($sql, 'insert')) { return $this->pdo->lastInsertId(); } return $count; }
/** * Obtem o ultimo ID inserido independente do tipo de query * @return int */ public static function lastInsertId() { if (CRUDQuery::isPDOMode()) { return self::$conn->lastInsertId(); } elseif (CRUDQuery::isMySqliMode()) { return mysqli_insert_id(CRUDQuery::getConn()); } }
public function insert(array $data) { self::prepareDataToSave($data); $lastInsertId = 0; $fields = implode(', ', array_keys($data)); $values = implode(', ', $data); //echo "INSERT INTO {$this->_tableName} ({$fields}) VALUES( $values );"; $this->setSqlQuery("INSERT INTO {$this->_tableName} ({$fields}) VALUES( {$values} );")->execQuery(); $lastInsertId = $this->getNumRows() ? $this->_PDOmySQLConn->lastInsertId() : 0; return $lastInsertId; }
/** * {@inheritDoc} * * @param string $table_name of table of last insert * @return string the ID of the insert */ function insertID($table_name = "") { if ($table_name && $this->to_upper_dbms == "PGSQL") { $table_name .= "_ID_SEQ"; $id = $this->pdo->lastInsertId($table_name); if (!$id) { //if sequence number somehow was renamed $id = $this->pdo->lastInsertId($table_name . "1"); } return $id; } return $this->pdo->lastInsertId(); }
/** * 执行写入语句 * * @access public * @param $sql * @return int|false */ public function execute($sql) { $this->connect(); if (!$this->_linkId) { return false; } try { $this->_numRows = $this->_linkId->exec($sql); } catch (PDOException $e) { trigger_error('MySQL PDO execute error: ' . $e->getMessage() . ' [' . $sql . ']'); } $lastInsID = $this->_linkId->lastInsertId(); return $lastInsID ? $lastInsID : $this->_numRows; }
/** * 获得刚插入数据的ID号 * * @return Int */ function insertId() { if ($this->type == "PDO") { return $this->conn->lastInsertId(); } else { if ($this->type == "SQLite3") { return $this->conn->lastInsertRowID(); } else { if ($this->type == "SQLite2") { return sqlite_last_insert_rowid($this->conn); } } } }
/** * Add a Feed * * @param String $feed_url ToDo desc * @param String $channel (optional) * * @return void */ public function onCommandFeedadd($feed_url, $channel = '') { $nick = $this->event->getNick(); if (empty($channel)) { $channel = $this->event->getSource(); } // Check if this feed already exists $sql = 'SELECT COUNT(*) FROM ft_feeds WHERE feed_url = ' . $this->db->quote($feed_url) . ' AND channel = ' . $this->db->quote($channel); if ((bool) $this->db->query($sql)->fetchColumn()) { $this->doNotice($nick, 'This feed already exists.'); return; } // Get Feed if (!($feed = $this->plugins->getPlugin('FeedTicker')->getFeed($feed_url))) { $this->doNotice($nick, 'Fail to get data from this feed.'); return; } // Parse Feed $FeedParser = $this->plugins->getPlugin('FeedParser'); if ($f = $FeedParser->parseFeed($feed['content'], $feed['header'])) { try { $defaultDelay = intval($this->getConfig('FeedTicker.defaultDelay', 300)); if ($defaultDelay < 60) { $defaultDelay = 60; } $q = $this->db->prepare('INSERT INTO ft_feeds ( updated, etag, delay, channel, title, description, link, feed_url, active ) VALUES ( :updated, :etag, :delay, :channel, :title, :description, :link, :feed_url, :active )'); $q->execute(array(':updated' => $f->updated, ':etag' => $f->etag, ':delay' => $defaultDelay, ':channel' => $channel, ':title' => $f->title, ':description' => $f->description, ':link' => $f->link, ':feed_url' => $feed_url, ':active' => true)); } catch (PDOException $e) { echo 'ERROR(FeedTicker): ' . $e . PHP_EOL; } if ($rowid = $this->db->lastInsertId()) { $this->doNotice($nick, "Done!"); $this->addItems($rowid, $f->items); $this->feeds = $this->getAllFeeds(); } else { $this->doNotice($nick, 'Bad things happened. Feed not saved.'); return; } } else { $this->doNotice($nick, "This feed is not valid/suported or is empty!"); } }
/** * Handles the tell/remind command (stores the message) * * @param string $recipient name of the recipient * @param string $message message to store * * @return void */ protected function handleRemind($recipient, $message) { // Don't do anything if we are only responding to targeted reminders and this isn't a targeted message. if ($this->onlyTargetedReminders && !$this->plugins->message->isTargetedMessage()) { return; } $source = $this->getEvent()->getSource(); $nick = $this->getEvent()->getNick(); $myself = $this->getConnection()->getNick(); if ($myself == $recipient) { $this->doPrivmsg($source, 'You can\'t send reminders to me.'); return; } if (!$this->getEvent()->isInChannel()) { $this->doPrivmsg($source, 'Reminders must be requested in-channel.'); return; } $q = $this->db->prepare('INSERT INTO remind ( time, channel, recipient, sender, message ) VALUES ( :time, :channel, :recipient, :sender, :message )'); try { $q->execute(array('time' => date(DATE_RFC822), 'channel' => $source, 'recipient' => strtolower($recipient), 'sender' => strtolower($nick), 'message' => $message)); } catch (PDOException $e) { } if ($rowid = $this->db->lastInsertId()) { $this->doPrivmsg($source, 'ok, ' . $nick . ', message stored'); } else { $this->doPrivmsg($source, $nick . ': bad things happened. Message not saved.'); return; } if ($this->keepListInMemory) { $this->msgStorage[$source][strtolower($recipient)] = $rowid; } }
/** * Handles the tell/remind command (stores the message) * * @param string $recipient name of the recipient * @param string $message message to store * * @return void */ protected function handleRemind($recipient, $message) { $source = $this->getEvent()->getSource(); $nick = $this->getEvent()->getNick(); if (!$this->getEvent()->isInChannel()) { $this->doPrivmsg($source, 'Reminders must be requested in-channel.'); return; } $q = $this->db->prepare('INSERT INTO remind ( time, channel, recipient, sender, message ) VALUES ( :time, :channel, :recipient, :sender, :message )'); try { $q->execute(array('time' => date(DATE_RFC822), 'channel' => $source, 'recipient' => strtolower($recipient), 'sender' => strtolower($nick), 'message' => $message)); } catch (PDOException $e) { } if ($rowid = $this->db->lastInsertId()) { $this->doPrivmsg($source, 'ok, ' . $nick . ', message stored'); } else { $this->doPrivmsg($source, $nick . ': bad things happened. Message not saved.'); return; } if ($this->keepListInMemory) { $this->msgStorage[$source][strtolower($recipient)] = $rowid; } }
/** * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column. * * @return string */ public function lastInsertId() { $this->_connect(); return $this->connection->lastInsertId(); }
/** * lasst insert id * @todo pgsql support * @param resource $connResource * @return int */ public function lastInsertId($connResource) { return $connResource->lastInsertId(); }
/** * Get the ID generated from the previous INSERT operation * * @return int * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ public function getInsertId() { $this->deprecated(); return $this->conn->lastInsertId(); }
/** * Execute a POST request. */ function post() { if ($this->table && $this->uid) { if ($this->requestData) { $primary = $this->getPrimaryKeys(); if ($primary && count($primary) == count($this->uid)) { // update a row $pairs = $this->parseRequestData(); $values = ''; foreach ($pairs as $column => $data) { $values .= '`' . $column . '` = "' . $this->db->escape($data) . '", '; } $values = substr($values, 0, -2); $where = ''; foreach ($primary as $key => $pri) { $where .= $pri . ' = \'' . $this->uid[$key] . '\' AND '; } $where = substr($where, 0, -5); $resource = $this->db->updateRow($this->table, $values, $where); if ($resource) { if ($this->db->numAffected() > 0) { $values = array(); foreach ($pairs as $column => $data) { $field = array('field' => $column, 'value' => $data); if (substr($column, -strlen($this->config['database']['foreignKeyPostfix'])) == $this->config['database']['foreignKeyPostfix']) { $field['xlink'] = $this->config['settings']['baseURL'] . '/' . substr($column, 0, -strlen($this->config['database']['foreignKeyPostfix'])) . '/' . $data . '/'; } $values[] = $field; } $this->output['row'] = $values; $this->generateResponseData(); } else { $this->badRequest(); } } else { $this->internalServerError(); } } else { $this->badRequest(); } } else { $this->lengthRequired(); } } elseif ($this->table) { // insert a row without a uid if ($this->requestData) { $pairs = $this->parseRequestData(); $values = join('", "', $pairs); $names = join('`, `', array_keys($pairs)); $resource = $this->db->insertRow($this->table, $names, $values); if ($resource) { if ($this->db->numAffected() > 0) { $this->created($this->config['settings']['baseURL'] . '/' . $this->table . '/' . $this->db->lastInsertId() . '/'); } else { $this->badRequest(); } } else { $this->internalServerError(); } } else { $this->lengthRequired(); } } else { $this->methodNotAllowed('GET, HEAD'); } }
/** * * @param string $tabla * @param array $data * @param resource $link_identifier * @return array */ function insertPDO($tabla, $data, $link_identifier = null) { $names = $values = array(); $tabla = (string) $tabla; $data = (array) $data; $return = array('success' => false, 'lastInsertId' => 0); if (!empty($tabla) && !empty($data)) { foreach ($data as $key => $value) { $names[] = (string) $key; $values[] = is_int($value) ? $value : "'{$value}'"; } $namesString = implode(', ', $names); $valuesString = implode(', ', $values); $sql = "INSERT INTO {$tabla} ( {$namesString} ) VALUES( {$valuesString} )"; $insert = $link_identifier->prepare($sql); $insert->execute(); $return['success'] = $insert; $return['lastInsertId'] = $link_identifier->lastInsertId(); } return $return; }
/** * Get last inserted id of the last query */ public function insertId() { return (int) $this->connection->lastInsertId(); }
/** * Create default records for domain if requested * * - SOA record (primary hostmaster serial refresh retry expire default_ttl) * - One entry for each NS * * @access public * @param array $values * @return void */ public function create_default_records($values) { // get last id $this->lastId = $this->Database_pdns->lastInsertId(); // set defaults $this->db_set_db_settings(); // content $soa = array(); $soa[] = array_shift(explode(";", $values['ns'])); $soa[] = str_replace("@", ".", $values['hostmaster']); $soa[] = $this->set_default_change_date(); $soa[] = $this->validate_refresh($values['refresh']); $soa[] = $this->validate_integer($values['retry']); $soa[] = $this->validate_integer($values['expire']); $soa[] = $this->validate_nxdomain_ttl($values['nxdomain_ttl']); // formulate SOA value $records[] = $this->formulate_new_record($this->lastId, $values['name'], "SOA", implode(" ", $soa), $values['ttl']); // formulate NS records $ns = explode(";", $values['ns']); if (sizeof($ns) > 0) { foreach ($ns as $s) { // validate if ($this->validate_hostname($s) === false) { $this->Result->show("danger", "Invalid NS" . " {$s}", true); } // save $records[] = $this->formulate_new_record($this->lastId, $values['name'], "NS", $s, $values['ttl']); } } // create records foreach ($records as $r) { $this->add_domain_record($r, false); } // all good, print it ! $this->Result->show("success", "Default records created", false); }
/** * Get last insert id * * @return int */ public function lastInsertId() { return $this->_conn->lastInsertId(); }
/** * 获取自增字段的最后一个值 * * @return mixed */ function insertId() { return $this->conn->lastInsertId(); }
/** * Return last insert ID * * @return integer */ public function lastInsertId() { return $this->link->lastInsertId(); }