当前位置: 首页>>代码示例>>PHP>>正文


PHP DatabaseConnection::lastInsertId方法代码示例

本文整理汇总了PHP中DatabaseConnection::lastInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::lastInsertId方法的具体用法?PHP DatabaseConnection::lastInsertId怎么用?PHP DatabaseConnection::lastInsertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection::lastInsertId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insert

 /**
  * Inserts an artist in database.
  *
  * @return bool True on success or false on failure
  */
 public function insert()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
     $connection = new DatabaseConnection();
     $query = $connection->prepare('INSERT INTO `artist` (`name`, `mbid`, `summary`, `country`) VALUES (:name, :mbid, :summary, :country);');
     $query->bindValue(':name', $this->name, PDO::PARAM_STR);
     $query->bindValue(':mbid', $this->mbid, PDO::PARAM_STR);
     $query->bindValue(':summary', $this->summary, PDO::PARAM_STR);
     $query->bindValue(':country', $this->country, PDO::PARAM_STR);
     if ($query->execute()) {
         $this->id = $connection->lastInsertId();
         //returns insertion was successfully processed
         return true;
     }
     //returns insertion has encountered an error
     return false;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:22,代码来源:Artist.php

示例2: insert

 /**
  * Inserts an album in database.
  *
  * @return bool True on success or false on failure
  */
 private function insert()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
     $connection = new DatabaseConnection();
     $query = $connection->prepare('INSERT INTO `album` (`name`, `mbid`, `artist`, `year`, `disk`, `country`, `mbidGroup`) VALUES ( :name, :mbid, :artist, :year, :disk, :country, :mbidGroup);');
     $query->bindValue(':name', $this->name, PDO::PARAM_STR);
     $query->bindValue(':mbid', $this->mbid, PDO::PARAM_STR);
     $query->bindValue(':artist', $this->artist, PDO::PARAM_INT);
     $query->bindValue(':year', $this->year, PDO::PARAM_INT);
     $query->bindValue(':disk', $this->disk, PDO::PARAM_INT);
     $query->bindValue(':country', $this->country, PDO::PARAM_STR);
     $query->bindValue(':mbidGroup', $this->mbidGroup, PDO::PARAM_STR);
     if ($query->execute()) {
         $this->id = $connection->lastInsertId();
         //returns insertion was successfully processed
         return true;
     }
     //returns insertion has encountered an error
     return false;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:25,代码来源:Album.php

示例3: insert

 /**
  * Inserts a track in database.
  *
  * @return bool True on success or false on failure
  */
 public function insert()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
     $connection = new DatabaseConnection();
     $query = $connection->prepare('INSERT INTO `track` (`file`, `album`, `year`, `artist`, `title`, `bitrate`, `rate`, `mode`, `size`, `time`, `track`, `mbid`, `updateTime`, `additionTime`, `composer`) VALUES (:file, :album, :year, :artist, :title, :bitrate, :rate, :mode, :size, :time, :track, :mbid, :update, :addition, :composer);');
     $query->bindValue(':file', $this->file, PDO::PARAM_STR);
     $query->bindValue(':album', $this->album, PDO::PARAM_INT);
     $query->bindValue(':year', $this->year, PDO::PARAM_INT);
     $query->bindValue(':artist', $this->artist, PDO::PARAM_INT);
     $query->bindValue(':title', $this->title, PDO::PARAM_STR);
     $query->bindValue(':bitrate', $this->bitrate, PDO::PARAM_INT);
     $query->bindValue(':rate', $this->rate, PDO::PARAM_INT);
     $query->bindValue(':mode', $this->mode, PDO::PARAM_STR);
     $query->bindValue(':size', $this->size, PDO::PARAM_INT);
     $query->bindValue(':time', $this->time, PDO::PARAM_INT);
     $query->bindValue(':track', $this->track, PDO::PARAM_INT);
     $query->bindValue(':mbid', $this->mbid, PDO::PARAM_STR);
     $query->bindValue(':update', time(), PDO::PARAM_INT);
     $query->bindValue(':addition', time(), PDO::PARAM_INT);
     $query->bindValue(':composer', $this->composer, PDO::PARAM_STR);
     if ($query->execute()) {
         $this->id = $connection->lastInsertId();
         //return true to indicate a successful track insertion
         return true;
     }
     //return false to indicate an error during track insertion
     return false;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:33,代码来源:Track.php

示例4: create

 /**
  * Create user with provided informations.
  *
  * @param object $user  User with his values attributes
  * @param string $error The returned error message
  *
  * @return bool True if the user is created
  */
 public function create($user, &$error)
 {
     $error = '';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
     $connection = new DatabaseConnection();
     $query = $connection->prepare('INSERT INTO `user` (`login`, `name`, `email`, `password`, `status`) VALUES (:login, :name, :email, :password, :status);');
     $query->bindValue(':login', $this->login, PDO::PARAM_STR);
     $query->bindValue(':name', $this->name, PDO::PARAM_STR);
     $query->bindValue(':email', $this->email, PDO::PARAM_STR);
     $query->bindValue(':password', md5($this->password), PDO::PARAM_STR);
     $query->bindValue(':status', $this->status, PDO::PARAM_INT);
     if ($query->execute() && $query->rowCount() > 0) {
         $this->id = $connection->lastInsertId();
         //return true to indicate a successful user creation
         return true;
     }
     $error = $query->errorInfo()[2];
     //try to return intelligible error
     if ($query->errorInfo()[1] === 1062 || $query->errorInfo()[2] === 'UNIQUE constraint failed: user.login') {
         $error = 'login `' . $this->login . '` already exists';
     }
     //return false to indicate an error occurred while creating user
     return false;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:32,代码来源:User.php


注:本文中的DatabaseConnection::lastInsertId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。