Php 无法解决此问题:致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[HY093]:无效参数编号:未定义参数”
这是我的代码,它不像我从头文件调用方法的最后一行。它声明无效的参数号,即使我调用的方法使用相同数量的参数。我不理解参数没有定义,因为$params是在调用之前定义的,并且$query从我的另一个文件中传递了一个值,我应该检查它是否已设置吗?该文件用于将来自另一个文件中表单的图像上载到imgurPhp 无法解决此问题:致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[HY093]:无效参数编号:未定义参数”,php,image,parameters,fatal-error,imgur,Php,Image,Parameters,Fatal Error,Imgur,这是我的代码,它不像我从头文件调用方法的最后一行。它声明无效的参数号,即使我调用的方法使用相同数量的参数。我不理解参数没有定义,因为$params是在调用之前定义的,并且$query从我的另一个文件中传递了一个值,我应该检查它是否已设置吗?该文件用于将来自另一个文件中表单的图像上载到imgur <?php include_once("connect.php"); class Image { public static function uploadImag
<?php
include_once("connect.php");
class Image
{
public static function uploadImage($formname,$query,$params)
{
$formname = "";
$response = "";
$image = "";
if(file_exists($formname))
{
$image = base64_encode(file_get_contents($_FILES[$formname]['tmp_name']));
}
$options = array('http'=>array(
'method'=>"POST",
'header'=>"Authorization: Bearer n/a\n".
"Content-Type: application/x-www-form-urlencoded",
'content'=>$image
));
$context = stream_context_create($options);
$imgurURL = "https://api.imgur.com/3/image";
if ($_FILES[$formname]['size'] > 10240000) {
die('Image too big, must be 10MB or less!');
}
if(file_exists($formname))
{
$response = file_get_contents($imgurURL, false, $context);
}
$response = json_decode($response);
$preparams = array($formname=>$response->data->link);
$params = $preparams + $params;
connect::query($query,$params);
}
}
?>
Here's my call to the uploadImage method with the value of $query
$postid = connect::query('SELECT id FROM dry_posts ORDER BY ID DESC LIMIT 1');
Image::uploadImage('postimg', "UPDATE dry_posts SET postimg=:postimg WHERE id=:postid", array(':postid'=>$postid));
下面是我的connect.php头文件:
<?php
class connect
{
private static function db()
{
$pdo = new PDO('mysql:host=127.0.0.1;dbname=mysql;charset = utf8', 'adereje','Abubba23');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
}
public static function query($query,$params = array())
{
$statement = self :: db()->prepare($query);
$statement->execute($params);
if(explode(' ',$query)[0] == 'SELECT')
{
$data = $statement->fetchAll();
return $data;
}
}
}
您刚刚将访问令牌发布到Internet。您应该立即使其过期。这太尴尬了。谢谢你,你注意到有什么需要修复的吗?你的$query的参数/占位符数量与实际的$params数组不同。如果需要帮助,请同时显示。我已将$query的值添加到我的帖子中,它位于以下调用中:Image::uploadImage'postimg',UPDATE dry_posts SET postimg=:postimg,其中id=:postid,array':postid'=>$postid;