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,
		]
	);
背字根微信二维码

本站文章均为原创,码字非常不容易,转载请注明原文出处,给苦逼的作者保留一点创作动力。