Created
September 18, 2017 03:54
-
-
Save mindevolution/55ed2ceaa966c146f535db37a6b99969 to your computer and use it in GitHub Desktop.
wordpress reset admin password - wordpress重置admin账号
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DB_HOST', 'localhost'); | |
define('DB_USER', 'nshore_admin'); | |
define('DB_PASS', 'w00d$ide'); | |
define('DB_NAME', 'npclients_wp'); | |
/** | |
* 数据库操作类 | |
*/ | |
class Db { | |
/** | |
* DB connection resource | |
* | |
* @var Resource | |
*/ | |
private $link; | |
/** | |
* 连接数据库 | |
*/ | |
public function __construct() { | |
$this->link = mysql_connect(DB_HOST, DB_USER, DB_PASS); | |
mysql_select_db(DB_NAME, $this->link); | |
} | |
/** | |
* 执行sql语句 | |
* | |
* @param string $sql sql statement | |
*/ | |
public function execute($sql) { | |
$result = mysql_query($sql); | |
while ($row = mysql_fetch_row($result)) { | |
print_r($row); | |
} | |
} | |
/** | |
* 插入数据 | |
* | |
* @param string $sql | |
* @return boolean | |
*/ | |
public function insert($sql) { | |
$result = mysql_query($sql); | |
return $result; | |
} | |
/** | |
* 更新数据 | |
* | |
* @param string $sql | |
* @return boolean | |
*/ | |
public function update($sql) { | |
$result = mysql_query($sql); | |
return $result; | |
} | |
/** | |
* 重置wp的admin密码 | |
*/ | |
public function resetAdminPW() { | |
$oldPassword = '$P$BYAF2jQTMTE0AiDs/YkvlZnAkNUn5F.'; | |
$sqlUpdateAdmin = <<<EOD | |
UPDATE `wp_users` SET `user_pass` = $oldPassword WHERE `wp_users`.`user_login` = "admin"; | |
EOD; | |
$this->update($sqlUpdateAdmin); | |
} | |
} | |
$db = new Db(); | |
// 测试查询 | |
$sql = 'select * from wp_users'; | |
$db->execute($sql); | |
// 更新wp的admin密码 | |
$sqlUpdateAdmin = <<<EOD | |
UPDATE `wp_users` SET `user_pass` = MD5( '1234' ) WHERE `wp_users`.`user_login` = "admin"; | |
EOD; | |
$result = $db->update($sqlUpdateAdmin); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment