WHMCS 6.0废弃update_query等数据库操作函数

文 / @WordPress主题

昨天发现WHMCS西数、景安虚拟主机模块手动续费后不更新时间,原本在写这两个模块时,在续费后会通过API取得主机到期时间,并更新WHMCS数据库。

查看官方文档才得知WHMCS 6.0已经废弃了以下数据库操作函数:

  • select_query()
  • update_query()
  • insert_query()
  • full_query()

新的版本中使用了Laravel 5.2框架的数据库组件,所以,对数据库的操作可以参考Laravel框架官方文档。

在WHMCS中,使用方法如下:

use Illuminate\Database\Capsule\Manager as Capsule;
foreach (Capsule::table('tblclients')->get() as $client) {
    echo $client->firstname . PHP_EOL;
}
try {
    $updatedUserCount = Capsule::table('tblclients')
        ->where('firstname', 'John')
        ->where('lastname', 'Deo')
        ->update(
            [
                'lastname' => 'Doe',
            ]
        );
 
    echo "Fixed {$updatedUserCount} misspelled last names.";
} catch (\Exception $e) {
    echo "I couldn't update client names. {$e->getMessage()}";
}

在我的模块中,主要是更新主机到期时间,代码如下:

Capsule::table('tblhosting')
	->where('id', $params['serviceid'])
	->where('username', $params['username'])
	->update(
		[
			'nextduedate' => $nextduedate,
			'nextinvoicedate' => $nextduedate,
		]
	);
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。