如何在旧的 Whmcs 挂钩上使用 Capsule
How to use Capsule on old Whmcs hooks
我已经将 Whmcs 从 6 版本升级到 7.7 版本,并且想使用 Laravel 的 Capsule 选项而不是经典的 SQL 语法,但我 运行 遇到了执行问题。
尝试了 WHMCS 文档,但似乎无法正确获取胶囊数组。
<?php
/** old hook **/
add_hook('AdminClientServicesTabFields', 1, function($vars) {
$PID = $vars['id'];
$result = mysql_query("SELECT name,mid FROM tblping where id = '$PID'");
while ($data = mysql_fetch_array($result)) {
$var1 = $data['name'];
$var2 = $data['mid'];
}
return [
'var1' => $var1 ,
'var2' => $var2,
];
});
<?php
/** new hook **/
add_hook('AdminClientServicesTabFields', 1, function($vars) {
use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;
$PID = $vars['id'];
$result = Capsule::table(tblping')->select('name','mid')->where->('id', '=', '$PID')->get();
while ($data = mysql_fetch_array($result)) {
$var1 = $data['name'];
$var2 = $data['mid'];
}
return [
'var1' => $var1 ,
'var2' => $var2,
];
});
有兴趣的朋友,解决方法如下:
use WHMCS\Database\Capsule;
add_hook('AdminClientServicesTabFields', 1, function($vars) {
$PID = $vars['id'];
$result = Capsule::table('tblping')->select('name','mid')->where('id',$PID)->get();
$array= json_decode(json_encode($result), True);
$var1 = $array[0]['name'];
$var2 = $array[0]['mid];
return [ 'var1'=> $var1, 'var2'=> $var2]
});
我已经将 Whmcs 从 6 版本升级到 7.7 版本,并且想使用 Laravel 的 Capsule 选项而不是经典的 SQL 语法,但我 运行 遇到了执行问题。
尝试了 WHMCS 文档,但似乎无法正确获取胶囊数组。
<?php
/** old hook **/
add_hook('AdminClientServicesTabFields', 1, function($vars) {
$PID = $vars['id'];
$result = mysql_query("SELECT name,mid FROM tblping where id = '$PID'");
while ($data = mysql_fetch_array($result)) {
$var1 = $data['name'];
$var2 = $data['mid'];
}
return [
'var1' => $var1 ,
'var2' => $var2,
];
});
<?php
/** new hook **/
add_hook('AdminClientServicesTabFields', 1, function($vars) {
use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;
$PID = $vars['id'];
$result = Capsule::table(tblping')->select('name','mid')->where->('id', '=', '$PID')->get();
while ($data = mysql_fetch_array($result)) {
$var1 = $data['name'];
$var2 = $data['mid'];
}
return [
'var1' => $var1 ,
'var2' => $var2,
];
});
有兴趣的朋友,解决方法如下:
use WHMCS\Database\Capsule;
add_hook('AdminClientServicesTabFields', 1, function($vars) {
$PID = $vars['id'];
$result = Capsule::table('tblping')->select('name','mid')->where('id',$PID)->get();
$array= json_decode(json_encode($result), True);
$var1 = $array[0]['name'];
$var2 = $array[0]['mid];
return [ 'var1'=> $var1, 'var2'=> $var2]
});