为什么我在“Array”第 2 行:VALUES Array 处或附近出现此错误:语法错误?

我正在遵循此线程中给出的示例

为什么 insert 不起作用并且在 postresql 上不输出任何错误?

当我尝试使用此选项在数据库内插入多个值时;我遇到此错误“错误:“数组”第 2 行或附近的语法错误:VALUES 数组..”请问有什么帮助吗?下面是代码:


       …….


       "INSERT INTO people( mom, non, ooo)

      VALUES 

    ($1,   $2,  $3), 

   ($4,   $5,  $6),

   ($7,   $8,  $9),

   ($10, $11, $12)


  ON CONFLICT (mom) DO NOTHING";


   $rcon = pg_query_params($connection, $ins, 

   Array(

   [ $mom ,$non,  $kooo],

   [ $mom 1,$non1,  $kooo1],

   [ $mom 2,$non2,  $kooo2],

   [ $mom 3,$non3,  $kooo3]

       )

   );


   if(!$rcon){

   echo pg_last_error($connection);

       }else{

            echo "Record added to database</br>"; //success confirmation

      }



  This gives this error;  ERROR: bind message supplies 4 parameters, but prepared statement "" requires 12 

phpPostgreSQLsql插入


LEATH
浏览 98回答 2
2回答

墨色风雨

您正在为参数绑定提供数组的数组。试试这个:&nbsp; &nbsp; $rcon = pg_query_params($connection, $ins,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mom,&nbsp; $non,&nbsp; &nbsp;$kooo,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mom1, $non1,&nbsp; $kooo1,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mom2, $non2,&nbsp; $kooo2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mom3, $non3,&nbsp; $kooo3,&nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; );

守候你守候我

我不明白数组与你的问题有什么关系。据推测,您想要插入多行。那将是:INSERT INTO people( mom, non, ooo)VALUES&nbsp;&nbsp; &nbsp; ($1,&nbsp; &nbsp;$2,&nbsp; $3),&nbsp;&nbsp; &nbsp; ($4,&nbsp; &nbsp;$5,&nbsp; $6),&nbsp; &nbsp; ($7,&nbsp; &nbsp;$8,&nbsp; $9),&nbsp; &nbsp; ($10, $11, $12)ON CONFLICT (mom) DO NOTHING
打开App,查看更多内容
随时随地看视频慕课网APP