tp6.0.12安装composer
composer require aliyun/aliyun-tablestore-sdk-php完整代码
<?php
namespace app\controller;
use app\BaseController;
//tablestore
use Aliyun\OTS\Consts\ColumnTypeConst;
use Aliyun\OTS\Consts\PrimaryKeyTypeConst;
use Aliyun\OTS\Consts\RowExistenceExpectationConst;
use Aliyun\OTS\OTSClient as OTSClient;
class Index extends BaseController
{
public function index()
{
$otsClient = new OTSClient (array (
'EndPoint' => 'https://ts-instance2.cn-hangzhou.ots.aliyuncs.com',
'AccessKeyID' => '12MGOT8t',
'AccessKeySecret' => '123PibLT6TrWSrueuFp',
'InstanceName' => 'ts-instance2'
));
$request = array (
'table_name' => 'xuetang',
'primary_key' => array ( // 主键
array('xuetang_id', 123),
),
'max_versions' => 1
);
$response = $otsClient->getRow ($request);
dump($response);
exit;
}
报错如下:
think \ exception \ ErrorException
During inheritance of ArrayAccess: Uncaught think\exception\ErrorException: Return type of Google\Protobuf\Internal\RepeatedField::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\RepeatedField.php:233 Stack trace: #0 D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\RepeatedField.php(47): think\initializer\Error->appError(8192, 'Return type of ...', 'D:\phpEnv\www\t...', 233) #1 D:\phpEnv\www\tp1.com\vendor\composer\ClassLoader.php(571): include('D:\phpEnv\www\t...') #2 D:\phpEnv\www\tp1.com\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('D:\phpEnv\www\t...') #3 D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\Message.php(133): Composer\Autoload\ClassLoader->loadClass('Google\Protobuf...') #4 D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\Message.php(77): Google\Protobuf\Internal\Message->initWithGeneratedPool() #5 D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\FileDescriptorSet.php(37): Google\Protobuf\Internal\Message->__construct(NULL) #6 D:\phpEnv\www\tp1.com\vendor\google\protobuf\src\Google\Protobuf\Internal\DescriptorPool.php(60): Google\Protobuf\Internal\FileDescriptorSet->__construct() #7 D:\phpEnv\www\tp1.com\vendor\aliyun\aliyun-tablestore-sdk-php\src\OTS\ProtoBuffer\GPBMetadata\TableStore.php(374): Google\Protobuf\Internal\DescriptorPool->internalAddGeneratedFile('\n\xC1S\n\x11table_stor...') #8 D:\phpEnv\www\tp1.com\vendor\aliyun\aliyun-tablestore-sdk-
这个包还没有兼容 PHP 8.1,出错的是 PHP 8.1 compatibility · Issue #13 · protocolbuffers/protobuf-php 这个包,不过这个包只是一个镜像,不应该作为直接依赖,需要参考 另外这个仓库 protobuf/php at master · protocolbuffers/protobuf