本文整理汇总了PHP中DatabaseConnection::insertRow方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::insertRow方法的具体用法?PHP DatabaseConnection::insertRow怎么用?PHP DatabaseConnection::insertRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::insertRow方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assignCredentials
/**
* Update the sign-in credentials for the specific user.
*
* @param UserRecord $user The user to update the credentials for
* @return Boolean True on success
*/
public function assignCredentials(UserRecord $user)
{
$db = new DatabaseConnection();
// Generate a new salt and hash the password
$salt = $this->generateSalt();
// What hashing algorithm to use
$ha = config::get('lepton.user.hashalgorithm', 'md5');
$ps = $user->password . $salt;
$hp = hash($ha, $ps);
if ($user->userid == null) {
$uuid = UUID::v4();
try {
$id = $db->insertRow("REPLACE INTO " . LEPTON_DB_PREFIX . "users (username,salt,password,email,flags,registered,uuid) VALUES (%s,%s,%s,%s,%s,NOW(),%s)", $user->username, $salt, $hp, $user->email, $user->flags, $uuid);
$user->userid = $id;
} catch (Exception $e) {
throw $e;
// TODO: Handle exception
}
} else {
try {
$db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "users SET username=%s,salt=%s,password=%s,email=%s,flags=%s WHERE id=%d", $user->username, $salt, $hp, $user->email, $user->flags, $user->userid);
} catch (Exception $e) {
throw $e;
// TODO: Handle exception
}
}
return true;
}
示例2: savepost
function savepost()
{
$post = new WebForm($this->gbform);
if (!$post->isValid()) {
// Form is invalid, post it back to the user to allow correction
} else {
$db = new DatabaseConnection();
$db->insertRow("INSERT INTO guestbook (name,email,website,message) VALUES (%s,%s,%s,%s)", $post->name, $post->email, $post->website, $post->message);
}
}
示例3: addEvent
public function addEvent(AuditEvent $event)
{
$event->setComponent($this->_component);
$cn = get_class($event);
$sev = serialize($event);
// Shove into DB -- echo $sev;
echo $cn . "\n\n" . $sev . "\n";
$db = new DatabaseConnection();
$db->insertRow("INSERT INTO auditlog " . "eventclass,component,severity,eventdate,data) " . "VALUES (%s,%s,%d,%d,NOW(),%s)", $cn, $event->getComponent(), $event->getSeverity(), $event->getAssociatedUserId(), $sev);
}
示例4: alias
/**
*
*
*
*
*/
public function alias()
{
$this->checkData();
console::writeLn("Generating geoalias table");
$db = new DatabaseConnection();
$db->exec('DROP TABLE IF EXISTS geoalias');
$db->exec('CREATE TABLE geoalias (id INT PRIMARY KEY AUTO_INCREMENT, geoid BIGINT, locname VARCHAR(64) CHARSET utf8, INDEX locname(locname(5))) CHARSET utf8');
$rows = $db->getRows("SELECT id,alternatenames FROM geonames WHERE alternatenames!=''");
console::write('%8d / %8d ', 0, count($rows));
foreach ($rows as $row) {
$alt = explode(',', $row['alternatenames']);
foreach ($alt as $altstr) {
$db->insertRow("INSERT INTO geoalias (geoid,locname) VALUES (%d,%s)", $row['id'], $altstr);
}
$rc++;
$rt++;
if ($rt >= 100) {
$rh++;
if ($rh >= 50) {
console::write("\n%8d / %8d ", $rc, count($rows));
$rh = 0;
} else {
console::write('.');
}
$rt = 0;
}
}
console::writeLn(' Done!');
}
示例5: save
public function save()
{
if (!$this->uuid) {
$this->uuid = uuid::v4();
}
if (count($this->modified) > 0) {
// Get a database reference
$db = new DatabaseConnection();
// Determine what needs to be updated.
$mtable = array('user' => false, 'userdata' => false, 'ambient' => false, 'credentials' => false);
foreach ($this->modified as $mod) {
switch ($mod) {
case 'ambient':
$mtable['ambient'] = true;
break;
case 'username':
$mtable['user'] = true;
break;
case 'password':
$mtable['credentials'] = true;
break;
case 'email':
$mtable['user'] = true;
break;
case 'uuid':
$mtable['user'] = true;
break;
case 'active':
$mtable['user'] = true;
break;
case 'displayname':
$mtable['userdata'] = true;
break;
case 'firstname':
$mtable['userdata'] = true;
break;
case 'lastname':
$mtable['userdata'] = true;
break;
case 'sex':
$mtable['userdata'] = true;
break;
case 'country':
$mtable['userdata'] = true;
break;
case 'flags':
$mtable['user'] = true;
break;
case 'userid':
break;
default:
throw new BadArgumentException("Unknown field modified: {$mod}");
}
}
$this->modified = array();
if (!$this->userid) {
// Check to see if the username already exists
if (user::find($this->username)) {
throw new UserException("User already exists!");
}
// Insert
$ambient = serialize($this->ambient);
$this->userid = $db->insertRow("INSERT INTO " . LEPTON_DB_PREFIX . "users (username,email,uuid,flags,active,registered) VALUES " . "(%s,%s,%s,%s,%d,NOW())", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0);
$db->updateRow("INSERT INTO " . LEPTON_DB_PREFIX . "userdata (displayname,firstname,lastname,sex,country,ambient,id) VALUES " . "(%s,%s,%s,%s,%s,%s,%d)", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid);
// Update credentials
$backend = User::getAuthenticationBackend();
$backend->assignCredentials($this);
} else {
// Update
if ($mtable['ambient'] && $mtable['userdata']) {
// Update complete userdata table
$ambient = serialize($this->ambient);
$db->updateRow("Update " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s,ambient=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid);
} elseif ($mtable['ambient']) {
// Update the ambient column
$ambient = serialize($this->ambient);
$db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET ambient=%s WHERE id=%d ", $ambient, $this->userid);
} elseif ($mtable['userdata']) {
// Update the userdata columns
$db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $this->userid);
}
if ($mtable['user']) {
// Update users table
$db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "users SET username=%s,email=%s,uuid=%s,flags=%s,active=%s WHERE id=%d", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0, $this->userid);
}
if ($mtable['credentials']) {
// Update credentials
$backend = User::getAuthenticationBackend();
$backend->assignCredentials($this);
}
}
}
return true;
}
示例6: assignCredentials
/**
* Update the sign-in credentials for the specific user.
*
* @param UserRecord $user The user to update the credentials for
* @return Boolean True on success
*/
public function assignCredentials(UserRecord $user)
{
$db = new DatabaseConnection();
$hp = $this->hashPassword($user->password);
logger::debug("Updating password has for %s with '%s'", $user->username, $hp);
if ($user->userid == null) {
$uuid = UUID::v4();
try {
$id = $db->insertRow("REPLACE INTO " . LEPTON_DB_PREFIX . "users (username,password,email,flags,registered,uuid) VALUES (%s,%s,%s,%s,%s,NOW(),%s)", $user->username, $hp, $user->email, $user->flags, $uuid);
$user->userid = $id;
} catch (Exception $e) {
throw $e;
// TODO: Handle exception
}
} else {
try {
$db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "users SET username=%s,password=%s,email=%s,flags=%s WHERE id=%d", $user->username, $hp, $user->email, $user->flags, $user->userid);
} catch (Exception $e) {
throw $e;
// TODO: Handle exception
}
}
return true;
}
示例7: execute
function execute()
{
$db = new DatabaseConnection();
$stmt = "INSERT INTO " . $this->table . " ";
$rd = array();
foreach ($this->insert[0] as $key => $val) {
$rd[] = $key;
}
$stmt .= "(" . join(',', $rd) . ") VALUES ";
$si = array();
foreach ($this->insert as $row) {
$sr = array();
foreach ($row as $key => $val) {
$sr[] = $db->escape('%s', $val);
}
$si[] = '(' . join(',', $sr) . ')';
}
$stmt .= join(', ', $si);
return $db->insertRow($stmt);
}
示例8: updateSets
private static function updateSets(callback $callback = null)
{
// Update the callback if one is present
if ($callback) {
$callback->call('Updating sets...');
}
// Pull the country list
$db = new DatabaseConnection();
$rs = $db->getRows("SELECT isocode,capital FROM geonames_countryinfo");
foreach ($rs as $cc) {
$f = $db->getSingleRow("SELECT * FROM geonames_datasets WHERE setkey=%s", $cc['isocode']);
if (!$f) {
$db->insertRow("INSERT INTO geonames_datasets (setkey,setname,url,active) VALUES (%s,%s,%s,0)", $cc['isocode'], $cc['capital'], self::getUrl($cc['isocode'] . '.zip'));
}
}
if ($callback) {
$callback->call('All sets updated');
}
}