本文整理汇总了PHP中Query::generateInsertStm方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::generateInsertStm方法的具体用法?PHP Query::generateInsertStm怎么用?PHP Query::generateInsertStm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query::generateInsertStm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save($contact)
{
parent::save($contact, self::OBJECT_CLASS);
$data = array(DB::CONTACT_CONTACT => $contact->getContact(), DB::CONTACT_NAME => $contact->getName(), DB::CONTACT_USER => $contact->getUserId());
$this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $contact);
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
$c = $this->quickLoad($this->db->last_inserted_id());
return $c;
}
示例2: save
function save($comm)
{
parent::save($comm, self::OBJECT_CLASS);
$data = array(DB::COMMENT_COMMENT => $comm->getComment(), DB::COMMENT_POST => $comm->getPost(), DB::COMMENT_AUTHOR => $comm->getAuthor());
$rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $comm);
if ($this->db->affected_rows() != 1) {
throw new Exception("Errore durante l'inserimento dell'oggetto.");
}
//carico il post inserito.
$c = $this->quickLoad(intval($this->db->last_inserted_id()));
return $c;
}
示例3: save
function save($report)
{
parent::save($report, self::OBJECT_CLASS);
$data = array(DB::REPORT_TEXT => $report->getReport(), DB::REPORT_OBJECT_ID => $report->getObject()->getID(), DB::REPORT_OBJECT_CLASS => get_class($report->getObject()), DB::REPORT_USER => $report->getAuthor());
$rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $report);
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore. Riprovare.");
}
//aggiorno lo stato dell'oggetto che è stato segnalato.
$this->updateObjectState($report->getObject());
return $this->db->quickLoad($report->getID());
}
示例4: addFeedbackFrom
function addFeedbackFrom($user, $value)
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineFeedbackColumns();
$table = Query::getDBSchema()->getTable(TABLE_FEEDBACK);
$db->execute($s = Query::generateInsertStm($table, array(FEEDBACK_CREATOR => $user->getID(), FEEDBACK_SUBJECT => $this->getID(), FEEDBACK_VALUE => $value ? 1 : 0)), $table->getName(), $this);
if ($db->affected_rows() != 1) {
$db->display_error("User::addFeedbackFrom()");
}
//Genera un errore ma ritorna comunque $this
} else {
$db->display_connect_error("User::addFeedbackFrom()");
}
return $this->loadFeedback();
}
示例5: createTag
/**
* Crea un tag.
* @param string $tag
* @return TRUE se il tag è stato creato, FALSE altrimenti.
*/
static function createTag($tag)
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineTagColumns();
$table = Query::getDBSchema()->getTable(TABLE_TAG);
$data = array(TAG_NAME => $tag);
$db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $tag);
if ($db->affected_rows() == 1) {
return true;
} else {
return false;
}
} else {
$db->display_connect_error("TagManager::createTag()");
}
}
示例6: save
function save($post, $author, $vote)
{
parent::save($post, "Post");
parent::save($author, "User");
settype($vote, "boolean");
//elimino il vecchio voto
$this->db->execute(Query::generateDeleteStm($this->table, array(new WhereConstraint($this->table->getColumn(DB::VOTE_AUTHOR), Operator::EQUAL, intval($author->getID()), new WhereConstraint($this->table->getColumn(DB::VOTE_POST), Operator::EQUAL, intval($post->getID()))))), $this->table->getName(), array($author->getID(), $post->getID()));
//non controllo se è stato cancellato perché può non esserci
$data = array(DB::VOTE_VOTE => $vote ? 1 : 0, DB::VOTE_POST => intval($post->getID()), DB::VOTE_AUTHOR => intval($author->getID()));
$this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $data);
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
//carico il voto inserito.
$this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::VOTE_AUTHOR), Operator::EQUAL, intval($author->getID()), new WhereConstraint($this->table->getColumn(DB::VOTE_POST), Operator::EQUAL, intval($post->getID())))), array()), $this->table->getName(), $data);
if ($this->db->num_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
return true;
}
示例7: saveHistory
/**
* Salva l'oggetto nella cartella di storicizzazione.
* @param Object $object l'oggetto da salvare
* @param User $editor l'utente che lo modifica
* @param string $operation l'operazione che è stata fatta (modifica o eliminazione)
* @throws Exception lancia eccezione se non è riuscito a salvare l'oggetto.
* @return l'id della riga salvata.
*/
protected function saveHistory($object, $editor, $operation)
{
//$this->save($object);
if (!is_a($editor, "User")) {
throw new Exception("Non hai settato chi ha fatto la modifica.");
}
$modDate = $_SERVER["REQUEST_TIME"];
$data = array(DB::HISTORY_OBJECT => serialize($object), DB::HISTORY_DATE => date("Y/m/d G:i:s", $modDate), DB::HISTORY_EDITOR => $editor->getID(), DB::HISTORY_OPERATION => $operation);
$this->db->execute(Query::generateInsertStm($this->historyTable, $data), $this->historyTable, $object);
if ($this->db->affected_rows() != 1) {
throw new Exception("Errore salvando la precedente vesrione dell'oggetto. Riprovare.");
}
return $this->db->last_inserted_id();
}
示例8: save
function save($post)
{
parent::save($post, self::OBJECT_CLASS);
$data = array(DB::POST_TYPE => $post->getType());
if (!is_null($post->getTitle())) {
$data[DB::POST_TITLE] = $post->getTitle();
}
if (!is_null($post->getSubtitle())) {
$data[DB::POST_SUBTITLE] = $post->getSubtitle();
}
if (!is_null($post->getHeadline())) {
$data[DB::POST_HEADLINE] = $post->getHeadline();
}
if (!is_null($post->getTags())) {
$data[DB::POST_TAGS] = $post->getTags();
}
if (!is_null($post->getCategories())) {
// check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default
require_once 'manager/CategoryManager.php';
$new_cat = CategoryManager::filterWrongCategories(explode(",", $post->getCategories()));
if (is_null($post->getCategories()) || count($new_cat) == 0) {
$new_cat[] = self::DEFAULT_CATEGORY;
}
$post->setCategories(Filter::arrayToText($new_cat));
$data[DB::POST_CATEGORIES] = $post->getCategories();
}
if (!is_null($post->getContent())) {
if ($post->getType() == Post::NEWS || $post->getType() == Post::VIDEOREP) {
$data[DB::POST_CONTENT] = $post->getContent();
} else {
$data[DB::POST_CONTENT] = serialize($post->getContent());
}
}
if (!is_null($post->isVisible())) {
$data[DB::POST_VISIBLE] = $post->isVisible() ? 1 : 0;
}
if (!is_null($post->getAuthor())) {
$data[DB::POST_AUTHOR] = $post->getAuthor();
}
if (!is_null($post->getPlace())) {
$data[DB::POST_PLACE] = $post->getPlace();
}
$post->setCreationDate($_SERVER["REQUEST_TIME"]);
if (is_null($post->getPermalink())) {
}
$post->setPermalink($this->generatePermalink($post));
$data[DB::POST_PERMALINK] = $post->getPermalink();
$rand = "";
$count = 0;
while ($this->permalinkExists($post->getPermalink() . $rand)) {
if ($count >= 1000) {
throw new Exception("Attenzione! Hai troppi atricol che si chiamano in questo modo. Prova a cambiare titolo.");
}
//finché esiste già un permalink del genere, ne genero uno random.
$rand = "(" . rand(65535, $_SERVER["REQUEST_TIME"]) . ")";
$data[DB::POST_PERMALINK] = $post->getPermalink() . $rand;
$count++;
}
$data[DB::POST_CREATION_DATE] = date("Y-m-d G:i:s", $post->getCreationDate());
$rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $this);
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
//carico il post inserito.
$p = $this->load(intval($this->db->last_inserted_id()));
//salvo i tag che non esistono
if (isset($data[DB::POST_TAGS]) && !is_null($data[DB::POST_TAGS]) && trim($data[DB::POST_TAGS]) != "") {
require_once 'manager/TagManager.php';
TagManager::createTags(explode(",", $data[DB::POST_TAGS]));
}
//salvo lo stato del post perché l'utente potrebbe aver già modificato il suo "colore".
$this->updateState($p);
return $p;
}
示例9: getAccessCount
/**
* @deprecated
* Enter description here ...
* @param unknown_type $type
* @param unknown_type $id
*/
static function getAccessCount($type, $id)
{
if ($type == null || $type == "" || $id == null) {
return 0;
}
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineLogColumns();
$table = Query::getDBSchema()->getTable("AccessLog");
$exists = false;
if ($type == "Post") {
require_once 'post/PostManager.php';
return 0;
$exists = PostManager::postExists($id);
} else {
if ($type == "User") {
require_once 'user/UserManager.php';
return 0;
$exists = UserManager::userExists($id);
} elseif ($type == "Partner") {
//TODO: implementa Partner
// require_once 'post/PartnerManager.php';
// $exists = PartnerManager::partnerExists($id);
}
}
if ($exists) {
$wheres = array(new WhereConstraint($table->getColumn("alog_type"), Operator::EQUAL, $type), new WhereConstraint($table->getColumn("alog_id"), Operator::EQUAL, $id));
$db->execute($s = Query::generateSelectStm(array($table), array(), $wheres, array()));
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$data = array("alog_count" => ++$row["alog_count"]);
$db->execute($s = Query::generateUpdateStm($table, $data, $wheres), null, LOGMANAGER);
if ($db->affected_rows() == 1) {
return $row["alog_count"];
}
} else {
$data = array("alog_type" => $type, "alog_id" => $id);
$db->execute($s = Query::generateInsertStm($table, $data));
if ($db->affected_rows() == 1) {
}
return 1;
}
}
return 0;
}
}
示例10: save
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineUserColumns();
$table = Query::getDBSchema()->getTable(TABLE_USER);
$data = array();
if (isset($this->avatar)) {
$data[USER_AVATAR] = $this->getAvatar();
}
if (isset($this->birthday)) {
$data[USER_BIRTHDAY] = date("Y/m/d", $this->getBirthday());
}
if (isset($this->birthplace)) {
$data[USER_BIRTHPLACE] = $this->getBirthplace();
}
if (isset($this->email)) {
$data[USER_E_MAIL] = $this->getEMail();
}
if (isset($this->gender)) {
$data[USER_GENDER] = $this->getGender();
}
if (isset($this->hobbies)) {
$data[USER_HOBBIES] = $this->getHobbies();
}
if (isset($this->job)) {
$data[USER_JOB] = $this->getJob();
}
if (isset($this->livingPlace)) {
$data[USER_LIVINGPLACE] = $this->getLivingPlace();
}
if (isset($this->name)) {
$data[USER_NAME] = $this->getName();
}
if (isset($this->nickname)) {
$data[USER_NICKNAME] = $this->getNickname();
}
if (isset($this->password)) {
$data[USER_PASSWORD] = $this->getPassword();
}
if (isset($this->role)) {
$data[USER_ROLE] = $this->getRole();
}
if (isset($this->surname)) {
$data[USER_SURNAME] = $this->getSurname();
}
if (isset($this->visible)) {
$data[USER_VISIBLE] = $this->getVisible() ? 1 : 0;
}
$db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
$db->execute(Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(USER_ID), Operator::EQUAL, $this->getID())), array()));
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[USER_CREATION_DATE])));
return $this;
} else {
$db->display_error("User::save()");
}
} else {
$db->display_error("User::save()");
}
} else {
$db->display_connect_error("User::save()");
}
return false;
}
示例11: save
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineMailColumns();
$table = Query::getDBSchema()->getTable(TABLE_MAIL);
$data = array();
if (isset($this->subject) && !is_null($this->getSubject())) {
$data[MAIL_SUBJECT] = $this->getSubject();
}
if (isset($this->from) && !is_null($this->getFrom())) {
$data[MAIL_FROM] = intval($this->getFrom());
}
if (isset($this->to) && !is_null($this->getTo())) {
$data[MAIL_TO] = $this->getTo();
}
if (isset($this->text) && !is_null($this->getText())) {
$data[MAIL_TEXT] = $this->getText();
}
if (isset($this->repliesTo) && !is_null($this->getRepliesTo())) {
$data[MAIL_REPLIES_TO] = intval($this->getRepliesTo());
}
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . $db->affected_rows(); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID(intval($db->last_inserted_id()));
//echo "<br />" . serialize($this->ID); //DEBUG
$rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(MAIL_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[MAIL_CREATION_DATE])));
//echo "<br />" . serialize($row[MAIL_CREATION_DATE]); //DEBUG
//inserisce il messaggio nelle mailbox dei $to
$toes = explode("|", $this->getTo());
//echo serialize($toes); //DEBUG
require_once "mail/MailManager.php";
for ($i = 0; $i < count($toes); $i++) {
$dir = MailManager::loadDirectoryFromName(MAILBOX, intval($toes[$i]));
MailManager::addMailToDir($this, $dir);
}
//echo "<br />" . $this; //DEBUG
return $this;
} else {
$db->display_error("Mail::save()");
}
} else {
$db->display_error("Mail::save()");
}
} else {
$db->display_connect_error("Mail::save()");
}
return false;
}
示例12: save
/**
* Salva il post e le sue dipendenze nel database.
* Le dipendenze salvate sono quelle che dipendono dall'autore ovvero: tag e categorie.
* Potrebbe salvare alcune tuple in Tag.
*
* @return: ID della tupla inserita (o aggiornata), FALSE se c'è un errore.
*/
function save()
{
require_once "post/PostCommon.php";
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
definePostColumns();
$table = Query::getDBSchema()->getTable(TABLE_POST);
$data = array(POST_TYPE => $this->getType());
if (isset($this->title) && !is_null($this->getTitle())) {
$data[POST_TITLE] = $this->getTitle();
}
if (isset($this->subtitle) && !is_null($this->getSubtitle())) {
$data[POST_SUBTITLE] = $this->getSubtitle();
}
if (isset($this->headline) && !is_null($this->getHeadline())) {
$data[POST_HEADLINE] = $this->getHeadline();
}
if (isset($this->tags) && !is_null($this->getTags())) {
$data[POST_TAGS] = $this->getTags();
}
if (isset($this->categories) && !is_null($this->getCategories())) {
// check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default
$new_cat = CategoryManager::filterWrongCategories(explode(",", $this->getCategories()));
if (!isset($this->categories) || is_null($this->getCategories()) || count($new_cat) == 0) {
$new_cat[] = self::DEFAULT_CATEGORY;
}
$this->setCategories(Filter::arrayToText($new_cat));
$data[POST_CATEGORIES] = $this->getCategories();
}
if (isset($this->content) && !is_null($this->getContent())) {
if ($this->type == "post" || $this->type == "news" || $this->type == "videoreportage") {
$data[POST_CONTENT] = $this->getContent();
} else {
$data[POST_CONTENT] = serialize($this->getContent());
}
}
if (isset($this->visible) && !is_null($this->isVisible())) {
$data[POST_VISIBLE] = $this->isVisible() ? 1 : 0;
}
if (isset($this->author) && !is_null($this->getAuthor())) {
$data[POST_AUTHOR] = $this->getAuthor();
}
if (isset($this->place) && !is_null($this->getPlace())) {
$data[POST_PLACE] = $this->getPlace();
}
$data[POST_PERMALINK] = $this->getPermalink();
if (self::permalinkExists($this->getPermalink())) {
//finché esiste già un permalink del genere, ne genero uno radfom.
$data[POST_PERMALINK] = $this->getPermalink() . "(" . rand(1024, $_SERVER["REQUEST_TIME"]) . ")";
}
$data[POST_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . $db->affected_rows(); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
//echo "<br />" . serialize($this->ID); //DEBUG
$rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
//echo "<br />" . serialize($rs); //DEBUG
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
//echo "<br />" . $row; //DEBUG
$this->setPermalink($row[POST_PERMALINK]);
$this->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[POST_CREATION_DATE])));
//salvo i tag che non esistono
if (isset($data[POST_TAGS]) && !is_null($data[POST_TAGS]) && trim($data[POST_TAGS]) != "") {
TagManager::createTags(explode(",", $data[POST_TAGS]));
}
//echo "<br />" . serialize($row[POST_CREATION_DATE]); //DEBUG
//echo "<br />" . $this; //DEBUG
return $this->ID;
} else {
$db->display_error("Post::save()");
}
} else {
$db->display_error("Post::save()");
}
} else {
$db->display_connect_error("Post::save()");
}
return false;
}
示例13: save
function save($cat)
{
parent::save($cat, self::OBJECT_CLASS);
$data = array();
if (!is_null($cat->getName())) {
$data[DB::CATEGORY_NAME] = $cat->getName();
}
if (!is_null($cat->getAuthorId())) {
$data[DB::CATEGORY_AUTHOR] = $cat->getAuthorId();
}
if (!is_null($cat->getCreationDate())) {
$data[DB::CATEGORY_CREATION_DATE] = date("Y-m-d G:i:s", $cat->getCreationDate());
}
$this->db->execute(Query::generateInsertStm($this->table, $data));
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
if (!is_null($cat->getParentName())) {
$this->db->execute(Query::generateInsertStm($this->table_sc, array(DB::SUB_CATEGORY_CATEGORY => $cat->getName(), DB::SUB_CATEGORY_PARENT => $cat->getParentName())));
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
}
return $cat;
}
示例14: addFollower
function addFollower($user)
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineFollowColumns();
$table = Query::getDBSchema()->getTable(TABLE_FOLLOW);
$db->execute($s = Query::generateInsertStm($table, array(FOLLOW_FOLLOWER => $user->getID(), FOLLOW_SUBJECT => $this->getID())), $table->getName(), $this);
if ($db->affected_rows() != 1) {
$db->display_error("User::addFollower()");
}
//Genera un errore ma ritorna comunque $this
} else {
$db->display_connect_error("User::addFollower()");
}
return $this->loadFollowers();
}
示例15: save
function save($resource)
{
parent::save($resource, self::OBJECT_CLASS);
$this->logger->debug("ResourceDao", "salvo risorsa " . $resource->getPath());
$data = array(DB::RESOURCE_OWNER => $resource->getOwnerId(), DB::RESOURCE_PATH => $resource->getPath(), DB::RESOURCE_TYPE => $resource->getType());
if (!is_null($resource->getDescription())) {
$data[DB::RESOURCE_DESCRIPTION] = $resource->getDescription();
}
if (!is_null($resource->getTags())) {
$data[DB::RESOURCE_TAGS] = $resource->getTags();
}
$data[DB::POST_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
$this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $this);
if ($this->db->affected_rows() != 1) {
throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
}
$r = $this->quickLoad($this->db->last_inserted_id());
//DEBUG
//var_dump($this->db->last_inserted_id());
//inserisco i tag nuovi
if (!is_null($resource->getTags()) && trim($resource->getTags()) != "") {
TagManager::createTags(explode(",", $resource->getTags()));
}
//salvo lo stato della risorsa perché l'utente potrebbe aver già modificato il suo "colore".
$this->updateState($r);
return $r;
}