未捕获异常';PDO异常';带有消息';MS Server PHP上的SQLSTATE[22007]
您好,我收到以下错误,当发出post请求时,我正在使用MS服务器、MSSQL数据库和php作为Oauth2解决方案 致命错误:未捕获的异常“PDOException”,消息为“SQLSTATE[22007]:[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]将nvarchar数据类型转换为日期时间数据类型导致值超出范围。'in C:\xampp\htdocs\api\OAuth2\Storage\Pdo.php:156堆栈跟踪:#0 C:\xampp\htdocs\api\OAuth2\Storage\Pdo.php(156):PDOStatement->execute(Array)#1c:\xampp\htdocs\api\OAuth2\ResponseType\AccessToken.php(84):OAuth2\Storage\Pdo->setAccessToken('02742b6cd16424e…','testclient',NULL,1465910857,NULL)#2c:\xampp\htdocs\api\OAuth2\GrantType\ClientCredentials.php(58):OAuth2\ResponseType\AccessToken->createAccessToken('testclient',,NULL,NULL,NULL,false)#3 C:\xampp\htdocs\api\OAuth2\Controller\TokenController.php(205):OAuth2\GrantType\ClientCredentials->createAccessToken(对象(OAuth2\ResponseType\AccessToken),'testclient',NULL,NULL)#4 C:\xampp\htdocs\api\OAuth2\Controller\TokenController.php(49):OAuth2\Controller\TokenController->->grantAccessToken(对象(OAuth2\Request),对象(第156行C:\xampp\htdocs\api\OAuth2\Storage\Pdo.php中的OAuth2\Response 在做了一些研究之后,我了解到22007与日期问题有关,我已经更改了日期的格式 下面是服务器抱怨的Pdo.php中的代码块未捕获异常';PDO异常';带有消息';MS Server PHP上的SQLSTATE[22007],php,sql-server,oauth-2.0,file-get-contents,Php,Sql Server,Oauth 2.0,File Get Contents,您好,我收到以下错误,当发出post请求时,我正在使用MS服务器、MSSQL数据库和php作为Oauth2解决方案 致命错误:未捕获的异常“PDOException”,消息为“SQLSTATE[22007]:[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]将nvarchar数据类型转换为日期时间数据类型导致值超出范围。'in C:\xampp\htdocs\api\OAuth2\Storage\Pdo.php:156堆栈跟踪:#0 C:
public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope = null)
{
//convert expires to datestring
//$expires = date('Y-m-d H:i:s', $expires);
$expires = date("Ymd H:i:s", $expires);
//echo $expires . "-------------------";
// if it exists, update it.
if ($this->getAccessToken($access_token)) {
$stmt = $this->db->prepare(sprintf('UPDATE %s SET client_id=:client_id, expires=:expires, user_id=:user_id, scope=:scope where access_token=:access_token', $this->config['access_token_table']));
} else {
$stmt = $this->db->prepare(sprintf('INSERT INTO %s (access_token, client_id, expires, user_id, scope) VALUES (:access_token, :client_id, :expires, :user_id, :scope)', $this->config['access_token_table']));
}
return $stmt->execute(compact('access_token', 'client_id', 'user_id', 'expires', 'scope'));
}
奇怪的是,在终端和邮递员中,当我运行curl post时,我在token.php上运行请求时得到了正确的响应
我们服务器上的php_curl.dll有一个问题,这意味着我必须使用file_get_contents post请求来获取数据
public function getAccess() {
$postdata = http_build_query ( array (
'client_id' => 'testclient',
'client_secret' => 'testpass',
'grant_type' => 'client_credentials'
)
);
$opts = array (
'http' => array (
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create ( $opts );
$result = file_get_contents ( 'http://IPADDRESS/api/token.php', false, $context );
// var_dump($result);
echo $result;
return $result;
}
我猜问题与使用file_get_内容有关,因为访问令牌是由终端和邮递员创建的
如有任何建议,将不胜感激
谢谢。值超出字段类型范围我已更改日期格式,当前格式允许使用邮递员和从终端/命令行创建令牌值超出字段类型范围我已更改日期格式,当前格式允许使用邮递员和从t创建令牌终端/命令行