我在尝试将此数组输出插入 codeigniter 3 中的 mysql 数据库时遇到了挑战

问题描述 投票:0回答:0

**enter code here**
我是第一次使用 CodeIgniter 开发人员,我正在开发一个自我诊断 Web 应用程序。在这个应用程序中,我有一个选项卡,用户可以在其中输入他们的症状,系统将根据输入生成结果。我面临的挑战是我想将系统的输出保存到 mysql 数据库表中。

为了自我诊断,我集成了一个chatgpt API。下面是为用户打印输出的代码片段


 <?php
  //  $this->load->database();

if(isset($_POST['str'])){

    $ch = curl_init();
    $str=$_POST['str'];
    curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $postdata=array(
        "model"=> "text-davinci-003",
        "prompt"=> $str,
        "temperature"=> 0.7,
        "max_tokens"=> 1400,
        "top_p"=> 1,
        "frequency_penalty"=> 0,
        "presence_penalty"=> 0
      );
    $postdata=json_encode($postdata);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    
    $headers = array();
    $headers[] = 'Content-Type: application/json';

    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);

    $result=json_decode($result,true);
    echo $result['choices'] [0] ['text'];
}


Two errors:
1. 
Severity: Notice

Message: Array to string conversion

Filename: database/DB_driver.php

Here's the error number 2
Error Number: 1054

Unknown column 'Array' in 'field list'

INSERT INTO `responses` (`responses`) VALUES (Array)
php mysql codeigniter-3
© www.soinside.com 2019 - 2024. All rights reserved.