RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-352732

Valentin's questions

Martin Hope
Valentin
Asked: 2023-09-29 20:53:58 +0000 UTC

为什么在输出 SELECT 的循环内连接到一个数据库的 INSERT 会给出 SELECT 错误?

  • 3

大家好!

我的主机上有两个网站,每个网站都有自己的数据库。在两个 WordPress 网站上。我想将一个类别的所有新闻从一个网站转移到另一个网站。我已经了解到Wordpress对此有一个现成的机制。但首先我尝试在旧数据库中选择并在新数据库中插入。我想知道为什么这不起作用:

<?php

$servername = "localhost";
$database = "xxxxxxxxxx";
$username = "xxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";

$servername2 = "localhost";
$database2 = "xxxxxxxxxxxxxx";
$username2 = "xxxxxxxxxxxxx";
$password2 = "xxxxxxxxxxxxx";

$conn = mysqli_connect($servername, $username, $password, $database);

$conn2 = mysqli_connect($servername2, $username2, $password2, $database2);

$sql = "SELECT * FROM wp_posts";

$counter = 600;

$iterator = 1;

if($result = $conn->query($sql)){
    foreach($result as $row){

        $stringArr[] = "(" . $counter . ", '" . $row['post_author'] . "', '" . $row['post_date'] . "', '" . $row['post_date_gmt'] . "',
        '" . $row['post_content'] . "', '" . $row['post_title'] . "', '" . $row['post_excerpt'] . "',
        '" . $row['post_status'] . "', '" . $row['comment_status'] . "', '" . $row['ping_status'] . "',
        '" . $row['post_password'] . "', '" . $row['post_name'] . "', '" . $row['to_ping'] . "',
        '" . $row['pinged'] . "', '" . $row['post_modified'] . "', '" . $row['post_modified_gmt'] . "',
        '" . $row['post_content_filtered'] . "', '" . $row['post_content_filtered'] . "', " . $row['post_parent'] . ",
        '" . $row['guid'] . "', " . $row['menu_order'] . ", '" . $row['post_type'] . "', '" . $row['post_mime_type'] . "',
        " . $row['comment_count'] . ")"; 
/*        
        if($iterator%50 == 0) {
            print_r($stringArr);

            exit;
        }*/
        $iterator++;
        $counter++;
 /*       
        print_r($string);
        
        $sql2 = "INSERT INTO serjam_wp1.wp_post VALUES (" . $string . ")";

        if ($conn2->query($sql2) === TRUE) {
          echo "New record created successfully";
        } else {
          echo "Error: " . $sql . "<br>" . $conn->error;
            }

如果将 INSERT 删除到第二个数据库中,则第一个数据库中的所有内容都会完美地显示在浏览器中。但是一旦 $sql2 使用 INSERT - 就是这样......

php
  • 1 个回答
  • 54 Views
Martin Hope
Valentin
Asked: 2023-09-27 16:41:02 +0000 UTC

我想将一些帖子从旧站点转移到新站点,但是 INSERT 到新数据库会在旧站点中出现错误 SELECT

  • 5

我的主机上有两个网站,每个网站都链接到自己的数据库。两者都在 WordPress 上。我正在尝试与两个数据库建立两个单独的连接,并从一个数据库下载信息并将信息放入另一个数据库中。这是我得到的:

<?php

$servername = "localhost";
$database = "xxxxxxxxxx";
$username = "xxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";

$servername2 = "localhost";
$database2 = "xxxxxxxxxxxxxx";
$username2 = "xxxxxxxxxxxxx";
$password2 = "xxxxxxxxxxxxx";

$conn = mysqli_connect($servername, $username, $password, $database);

$conn2 = mysqli_connect($servername2, $username2, $password2, $database2);

$sql = "SELECT * FROM wp_posts";

$counter = 600;

$iterator = 1;

if($result = $conn->query($sql)){
    foreach($result as $row){

        $stringArr[] = "(" . $counter . ", '" . $row['post_author'] . "', '" . $row['post_date'] . "', '" . $row['post_date_gmt'] . "',
        '" . $row['post_content'] . "', '" . $row['post_title'] . "', '" . $row['post_excerpt'] . "',
        '" . $row['post_status'] . "', '" . $row['comment_status'] . "', '" . $row['ping_status'] . "',
        '" . $row['post_password'] . "', '" . $row['post_name'] . "', '" . $row['to_ping'] . "',
        '" . $row['pinged'] . "', '" . $row['post_modified'] . "', '" . $row['post_modified_gmt'] . "',
        '" . $row['post_content_filtered'] . "', '" . $row['post_content_filtered'] . "', " . $row['post_parent'] . ",
        '" . $row['guid'] . "', " . $row['menu_order'] . ", '" . $row['post_type'] . "', '" . $row['post_mime_type'] . "',
        " . $row['comment_count'] . ")"; 
/*        
        if($iterator%50 == 0) {
            print_r($stringArr);

            exit;
        }*/
        $iterator++;
        $counter++;
 /*       
        print_r($string);
        
        $sql2 = "INSERT INTO serjam_wp1.wp_post VALUES (" . $string . ")";

        if ($conn2->query($sql2) === TRUE) {
          echo "New record created successfully";
        } else {
          echo "Error: " . $sql . "<br>" . $conn->error;
            }
        */
 //       print_r($string);
         
    }
}

$sql2 = "INSERT INTO serjam_wp1.wp_post VALUES (" . implode(",", $stringArr) . ")";

        if ($conn2->query($sql2) === TRUE) {
          echo "New record created successfully";
        } else {
          echo "Error: " . $sql . "<br>" . $conn->error;
            }

如果我只是在浏览器中显示数据库的内容(信息已经存在),那么我就可以得到一切。

也就是说,如果没有 INSERT 代码,则该脚本将起作用。但如果是,那么 SELECT 将停止工作。我从信息所在的站点运行脚本。

在此输入图像描述

wordpress
  • 1 个回答
  • 19 Views
Martin Hope
Valentin
Asked: 2022-09-01 22:28:34 +0000 UTC

PHP:你能告诉我如何应用 Exception 类吗?我无法在文档中弄清楚

  • 0

我开始学习 Exception 课程,如果这个问题对某人来说很愚蠢,我深表歉意。我想在我的 MVC 提案中使用异常继承。创建了一个继承自内置 Exception 类的 ErrorController 类。我在其中创建了 processServError() 方法,以便在其他类中使用它来处理所需的错误......

<?php

namespace Controller;

use Throwable;
use View\View;

use \Exception;

class ErrorController extends Exception
{
    private static $curlErr;

    function __construct($message = "", $code = 0, Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);
    }

    public static function processServError($curlErr) {
        return self::$curlErr;
    }

但是当在另一个文件中我尝试以这种方式引用生成的方法时:

if (!empty($curlErr)) {
            throw new ErrorController::processServError($curlErr);
        } else {

然后使用 throw 抛出异常不起作用.虽然其他静态类的其他静态方法工作正常...

然后如何使用来自 ErrorController 的各种错误的方法?请告诉我...

php
  • 1 个回答
  • 52 Views
Martin Hope
Valentin
Asked: 2022-08-29 17:55:16 +0000 UTC

PHP:如果 api 不起作用,如何在 curl 请求中获取服务器响应 http 标头?

  • 0

尊敬的专家!

我向一项服务的 api 提出请求。如果 api 已经掉线并且服务器不可用,那么 $ch 中将没有任何内容,尽管在正常的 api 操作期间,例如,如果输入了不正确的凭据,则会出现代码错误。如果 api 在技术上不可用(500 错误)或由于其他原因不返回任何内容,如何在 curl 请求期间获取带有响应状态的标头。尝试添加 curl_setopt($ch, CURLOPT_HEADER, 1); 但是请求因此停止工作,并且不仅返回http标头,还返回成功请求的结果(没有这个我得到一个json结构)。也试过

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); print_r($httpcode);

这次代码来了,但与 api 本身的 json 结构相同。假设其中的代码为 0 - 请求成功,那么 $httpcode 将是相同的...我怀疑如果 api 不可用,那里将什么都没有...请告诉我如何仍然获取 http - curl 请求时响应中带有错误状态的标头?

$data = array("user_name" => $this->log, "user_pass" => $this->pass);
        $ch = curl_init("$url");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLINFO_HTTP_CODE, true);

return json_decode(curl_exec($ch));
php
  • 1 个回答
  • 32 Views
Martin Hope
Valentin
Asked: 2022-08-07 16:57:01 +0000 UTC

JS:在 forEach 循环中使用 findIndex 的正确方法是什么?

  • 0

我刚刚开始学习 JS,所以我提前为这个问题道歉,这对于更有经验的人来说可能看起来很愚蠢。有一个训练代码:

<html>
<script>
let inputWord = 'mappet'

let lettersArr = inputWord.split('');
                
lettersArr.forEach(function(letter) {
    console.log(letter);
    let index = lettersArr.findIndex(i => i == letter);
    
    if(lettersArr[index] == 'p' && lettersArr[index + 1] == 'p') {
        
        lettersArr[index] = lettersArr[index] + '—';
       
    }
    
});

let withTransfer = lettersArr.join("");

alert(withTransfer);
</script>
</html>

如果 inputWord 变量包含单词“mappet”,那么它可以安全地工作,在两个“p”之间插入一个破折号,但如果它包含“pappet”或任何其他单词,其首字母重复了中间的两倍,那么条件不起作用。我认为这是因为 findIndex 它需要第一次出现字母并检查条件。在“pappet”的情况下,第一个条件将是启动所有内容的非双 p,因此它不会满足中间“pp”的条件。

请告诉我如何确保单词 pappet 中的第一个 p 不会干扰在中间插入破折号。我绞尽脑汁却什么也想不出来。

javascript массивы
  • 2 个回答
  • 57 Views
Martin Hope
Valentin
Asked: 2022-07-05 22:26:33 +0000 UTC

如何发送请求以使用 curl 计算算术平均值并在变量中获取响应?

  • 0

我正在尝试在 php / curl 中编写一个请求,以获取网站上表单中的算术平均值:

http://www.alcula.com/calculators/statistics/mean/#gsc.tab=0

在我看来,这很简单,很容易得出结果。然而,许多尝试都失败了:

$curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'http://www.alcula.com/calculators/statistics/mean/#gsc.tab=0');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, "data=5,6,7");
        $out = curl_exec($curl);
        echo $out;
        curl_close($curl); 

我试图像这样请求数字 5 6 7 的算术平均值,但出现了错误请求页面作为响应,请告诉我在这种情况下如何正确提取“卷曲”的算术平均值?不管我怎么努力,我什么都想不出来! 在此处输入图像描述

php
  • 1 个回答
  • 13 Views
Martin Hope
Valentin
Asked: 2022-04-12 15:24:13 +0000 UTC

PHP:如何在每个类函数中使变量可用?

  • 0

为什么我不能在 getInfFromTheSource()、selectWhatIsNeeded() 函数中传递 $open_config 变量。据我了解,为此,您需要将它们传递给构造函数并以下面代码中的方式处理它们。

class Downloader
{
    public $source_link, $source_html, $dom, $xpath, $open_config;
    
    function __construct($source_link, $source_html, $dom, $xpath, $open_config)
    {
        $this->source_link = $source_link; 

        $this->source_html = $source_html;

        $this->dom = $dom;

        $this->xpath = $xpath;
        
        $this->open_config = $open_config;
                
    }

    public function getInfFromTheSource ()
    {
        
        $open_config = json_decode(file_get_contents('config.json', true));

        $source_link = $open_config->InfSource;
        
        $source_html = file_get_contents($source_link);
        
        return($source_html);
        
    }
    
    public function selectWhatIsNeeded ($source_html) 
    {
       $open_config = json_decode(file_get_contents('config.json', true));
        $xpathstring = $open_config->string_for_xpath;

        $dom = new DOMDocument();
    
        $dom->loadHTML($source_html);
    
        $xpath = new DOMXpath($dom);
    
        $archives_names = $xpath->query('$xpathstring');
                
        return($names);
                    
    }

也许重点是我如何创建类的实例并访问方法?我将类文件包含在 required_once 中,然后:

$obj = new Downloader($source_link, $source_html, $dom, $xpath, $open_config);

$obj->selectWhatIsNeeded($obj->getInfFromTheSource());

我尝试将 $open_config 声明为全局的,我完全按照程序中的方式进行了操作,并且可以正常工作。但由于某种原因,它不能那样工作......大师,如果你有时间,你能建议最好的方法吗?

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-04-08 20:53:52 +0000 UTC

PHP:如何将一个类的工作结果转移到另一个类?

  • 0

我刚刚开始使用 OOP。我的程序分为几个类,我在 index.php 中调用它们的实例:

require_once('Parser.php');

require_once('Controller.php')

$obj = new Parser();

$obj->getMyInformation();

$obj2 = new Controller();

$obj2->putInformationInTables();

我希望一个类的“输出”作为“输入”在另一个类中处理。那么如何最好地将信息从 Parser() 类传递到 Controller() 类?

也许最优化的方法是通过类参数?像这样尝试:

$obj2 = new Controller(30);

$obj2 = new Controller(40);

但是值30和40并没有分配给Controller()类内部的任何变量。

我读到静态变量和构造函数用于此...但是它写得难以理解...我无法在我的代码中重复它...你能告诉我这些事情是如何正确完成的吗?

目前尚不清楚如何使类实例和类协调......

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-03-21 15:57:26 +0000 UTC

将任务交给 Open Server Task Scheduler 的正确方法是什么?

  • 0

我正在尝试按计划运行一个 php 脚本,以便它每小时运行一次。

在此处输入图像描述

该脚本使用以下命令在正确的时间成功运行:

E:\modules\wget\bin\wget.exe -q --no-cache http://localhost/par.php

问题是在我的会话脚本中,每次启动都应该从那里获取某些信息,因此,正如我在这里所建议的那样,我需要使用 php.exe 运行脚本。不幸的是,这里是:

E:\OpenServer\modules\php\PHP_7.1\php.exe -f --no-cache http://localhost/par.php

不想工作。

尝试了 Open Server 文档中的示例:

https://ospanel.io/docs/

E:\OpenServer\modules\php\PHP_7.1\php.exe -c E:\OpenServer\userdata\config\PHP_7.1_php.ini" -q -f E:\OpenServer\domains\localhost\par.php

那也行不通。有经验的高手,不告诉我怎么做对吗?很抱歉打扰并提前感谢您的帮助。

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-08-28 15:31:27 +0000 UTC

如何通过将嵌套数组键向上移动来重新组合数组?

  • 0

有一个数组数组,在foreach循环中处理:

$lc = [];

    foreach ($outputarr as $uy => $q) {
    
    
        $sq = $lc + $q;
    
    
    }

结果,每次迭代 $q 都会收到一个具有相同结构的数组。这是这些数组之一($q 一次迭代中的 wardumping 的结果):

array(1) {
  [15]=>
  array(1) {
    [2017]=>
    string(2) "10"
  }
}

合并来自 foreach 操作的所有数组,这些数组落入 $q,但不会在顶部添加新键。你需要这个结果:

array{

  [15]=>
  array(1) {
    [2017]=>
    string(2) "10"
  }
}

 [16]=>
  array(1) {
    [2017]=>
    string(2) "10"
  }
}
}

该示例的第一个代码片段中的代码不起作用,由于某种原因,数组没有加起来..

$lc = 数组();

    foreach ($outputarr as $uy => $q) {
    
    
        $sq = array_merge($lc, $q);
    
    
    }

这也不起作用,但如果你这样做:

  $lc = array();
        
            foreach ($outputarr as $uy => $q) {
            
            
                $sq[] = $q;
            
            
            }

然后 $sq 用数组填充,但添加了顶级键 [0]、[1]、[2] - 需要避免的事情......

不要告诉我谁知道该怎么做?非常感谢您!

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-08-24 20:33:00 +0000 UTC

PHP:如何在比较两个关联数组时获取差异数组,并只获取只出现在其中一个数组中的值?

  • 0

抱歉打扰你。我有这个问题,有两个数组:

一)

 $array1 = array(
'фрукт' => array('яблоко', 'груша', 'апельсин', 'лимон'),
'овощь' => array('кабачок', 'капуста', 'патисон'),
'ягода' => array('малина', 'земляника'),
);
$array2 = array(
'фрукт' => array('груша', 'слива', 'апельсин'),
'овощ' => array('кабачок', 'капуста', 'картошка'),
);

我们需要将第二个和第一个进行比较,得到一个新数组,其中只包含 $array2 中没有的值和键。$array1 可能包含根本不在 $array2 中的新键,并且可能在两个数组中都存在的相同键中找到新值。它在 $array1 中,但尚未添加到 $array2 中。请告诉我如何比较 $array1 和 $array2 并得到一个有差异的数组:如果 $array2 中有键,那么在 $array1 中只能找到一个新值,如果 $array2 中没有键,然后将一个新的添加到结果数组键及其所有值中。

你试过什么?

试过 $array_diff()、$array_diff_assoc()。第二个应该可以工作,但返回一个空数组,尽管两个数组存在差异。我试图用两个 foreach 编写自己的函数

foreach ($array1 as $fl) {
     foreach ($array2 as $subfl) {

}
}

它也没有工作...

php
  • 3 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-08-13 23:37:05 +0000 UTC

如何摆脱数组数组中的重复元素?

  • 0

同事!

有谁知道如何删除数组数组中的重复数组,即消除具有重复键、值和值值的元素...尝试以下示例:

$test = array_unique_key($test, 'id'); 
print_r($test);

但它也会删除那些键相同但某些值不同的元素。只array_unique给出二维数组的结果......

$test = array(
    array(
        'id' => 1,
        'name' => 'Диски Sparco',
        'price' => 5000,
    ),
    array(
        'id' => 1,
        'name' => 'Диски Sparco',
        'price' => 5000,
    ),
    array(
        'id' => 2,
        'name' => 'Диски Sparco',
        'price' => 6342,
    ),
);
php
  • 2 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-07-01 21:35:49 +0000 UTC

XPath:如何仅获取具有所需名称的父母内部的那些节点的内容?

  • 0

解析具有以下结构的html:

<div class="versions">
    <div class="meld" data-versions-items="2021 г.">
         <a href="https://www.englishforcing.ru/novosti/po-anglijski-v-budushhem-budut-govorit-s- 
         indijskim-akcentom-britanskij-lingvist/"></a>
    </div>
    
    <div class="meld" data-versions-items="2020 г.">
         <a href="https://www.englishforcing.ru/novosti/po-anglijski-v-budushhem-budut-govorit-s- 
         indijskim-akcentom-britanskij-lingvist/"></a>
    </div>
        <div class="meld" data-versions-items="2019 г.">
      <a href="https://www.englishforcing.ru/novosti/po-anglijski-v-budushhem-budut-govorit-s-indijskim-akcentom-britanskij-lingvist/"></a>
    </div>
</div>

我想使用 XPath 在一个请求中获取 2020 年、2019 年的所有链接,假设 2021 年,不要接受它..如何从所有节点获取所需年份的链接...?像这样尝试:

$document = new DOMDocument();
    $document->loadHTML($html);
    
    $xpath = new DOMXpath($document);

$elements = $xpath->query('//div[contains(@class,"versions")]');

所以:

$document = new DOMDocument();
        $document->loadHTML($html);
        
        $xpath = new DOMXpath($document);

$experiments = $xpath->query('//div[contains(@data-versions-items,"2020 г.")]');

对于 2020 年,它提供了信息,但我想在几年内不替换周期中的几个可能选项,因为那时会有几个 xpath zarpos,这是多余的..

是否有可能达到预期的结果以及如何实现?我不知道该尝试什么了。。

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-06-19 17:05:16 +0000 UTC

pg_query() 函数“说”:语法错误,而 pg_result_error() 输出一个空字符串,可能是什么问题?

  • 0

我正在尝试将数据加载到 Postgres 表中。脚本和数据位于本地 Open Server 服务器上,数据库位于另一台远程服务器上,我可以完全访问该服务器(我通过数据库管理器连接到数据库并编辑所有内容)。启动脚本时,连接数据库成功,但 INSERT INTO 查询不起作用:

$pg = "INSERT INTO public.1253_data () VALUES " . implode(",", $temp_array);

pg_query 函数抛出错误,写道:警告:pg_query():查询失败:语法错误(近似位置:.1253_data)。

我正在运行 pg_result_query() 函数:

$result = pg_query($conn, $sql);


 if ($result) {
   echo "New record created successfully";
} else {
      $k = pg_get_result($result);
      echo 'Query failed1: ' . pg_result_error($k);
}
pg_close($conn);

结果,pg_result_error 返回空:

在此处输入图像描述

从文档来看,pg_result_gives 只有在没有错误的情况下才会给出这个。但是为什么 pg_query 自己的错误描述符是这样的呢?

我刚刚开始学习 pg,我尝试了一切以寻找错误(专家,告诉我,它可能是什么?

php
  • 2 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-01-20 22:05:35 +0000 UTC

PHP:使用 PHPWord 库填充 Word 文档时如何提取 xml 节点的内容?

  • 1

请告诉我!

我将 Yandex 输出 xml 放入 $result 变量,使用 PHPWord 库方法将此耻辱发送到 Word 文档:

foreach ($tmp as $key => $value) {

    if (is_string($value)) {
        /*var_dump(substr($value, 21));*/
    $cut = $value;
   $output = 'https://yandex.ru/search/xml?user' . urlencode($cut) . 'xxxxxxxxxxxxx';

    $result = file_get_contents($output);
     
    $section->addText($result);

       $objWriter->save('helloWorld.docx');
       sleep(30);
   }

$result 变量中的通用 xml 被插入。它看起来像这样:

在此处输入图像描述

但是当然,我不需要文档中这样的 xml 片段。我正在尝试提取单个 xml 节点的内容并将它们也插入到 word 中,没有标签本身,但是 PHPWord 不想这样做。我做错了什么?我试图提取单个标签之间的内容,如下所示:

一)

preg_match_all('|<title>(.+)</title>|', $result, $match);
$section->addText($match);
$xml = simplexml_load_string($result);
$section->addText($xml);

一个或另一个选项都不起作用.. Word 文件已创建,但仍为空..

php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2022-01-15 22:58:03 +0000 UTC

为什么标签从内部循环到外部循环不起作用?

  • 1

你能告诉我下面的代码有什么问题吗?

控制台中不会显示任何错误,但标签不会转换到外部循环outer。

let fruits = ["Яблоко", "Апельсин", "Слива", "Груша", "Мандарин", "Лимон", "Дыня", "Гранат"];
        
let index;
        
let indx;
        
let a;
        
outer: for(;;) {
  for (indx = 0; indx < fruits.length; indx++) {
    if (indx === indx[5]) {
      break outer;
    }
    console.log(fruits[indx]);
  }
  console.log("a");
}
javascript
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2021-12-07 17:40:50 +0000 UTC

PHP:如何进入条件“循环结束”(没有什么可以迭代)?

  • 0

同事!如何编写一个 if 条件,以便如果数组以超过 100 个结尾,那么它的剩余部分仍将由 if 内的 INSERT 查询发送。我试过 if($stop%100 == 0 || $temp_array === end($value)),但是 $value 是一个数组,而 $temp_array 包含来自 $value 的几个数组(这就是请求发送一部分的原因这些数组)。请帮助我克服僵局..我将不胜感激任何建议..

foreach($assoc_array as $value) {
    
        $temp_array[] = "($value[year], '$value[is_sender]', '$value[is_receiver]', '$value[is_holder]', '$value[is_declarant]','$value[sender]', '$value[receiver]', '$value[holder]', '$value[declarant]', '$value[_sys_number]', '$value[_key]', '$value[_status]', '$value[inn]')";
    
        if( $stop%100 == 0) {
            $query =
                "INSERT INTO basename
                    (year,is_sender,is_receiver,is_holder,is_declarant,sender,receiver,holder,declarant,_sys_number,_key,_status,inn)
                VALUES " . implode(",", $temp_array);
            
            if ( !$b->Query( $query ) )
            {
                print("ERROR CONNECT SQL");
                exit;
            }
    
            $temp_array = array();
    
        }
    $stop++;
    
    }
php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2021-11-12 23:28:35 +0000 UTC

将变量的值从一个类方法传递给另一个类方法,最佳方法是什么?

  • 0

它里面有一个类和两个函数。在第二个函数中,您需要从函数 1 获得的变量的值。

class A {

function first {
**$result**
}

function second {
$arr [
'fruit' => $result,
'vegetable' => 'potato'
];
}
}

你能告诉我解决这个问题的最有效方法是什么吗?我尝试了许多不同的选择,但似乎没有任何效果......

我正在使用的特定代码:

class Auth
{
    public $url = "https://ддддддддддд/auth/login/";

    public $url2 = "https://auth.ооооооооо/billing/id/";

    public $credentials = [
        'user_name' => 'вававава',
        'user_pass' => 'вавававава',
        'product_code' => 'вавава'
    ];

    public function moveaway()
    {
        $access = json_encode($this->credentials);
        $getting = curl_init($this->url);
        curl_setopt($getting, CURLOPT_POST, 1);
        curl_setopt($getting, CURLOPT_POSTFIELDS, $access);
        curl_setopt($getting, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($getting, CURLOPT_SSL_VERIFYPEER, false);
        $output = curl_exec($getting);
        curl_close($getting);
        $decode = json_decode($output, true);
        $sidfinal = $decode['data']['SID'];
        global $sidfinal;
    }

    public function cid()
    {
        echo self::$sidfinal;
        $second = [
            'sid' => $sidfinal,
            'ogrn' => 1071650001796
        ];
        $injson = json_encode($this->second);
        $nextstep = curl_init($this->url2);
        curl_setopt($nextstep, CURLOPT_POST, 1);
        curl_setopt($nextstep, CURLOPT_POSTFIELDS, $injson);
        curl_setopt($nextstep, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($nextstep, CURLOPT_SSL_VERIFYPEER, false);
        $output2 = curl_exec($nextstep);
        curl_close($nextstep);
        echo $output2;
    }
}

$h = new Auth();
$h->moveaway();
$h->cid();
php
  • 1 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2021-11-06 23:10:02 +0000 UTC

为什么 cURL 不能通过 url 连接到 api?

  • 0

使用 cURL 安装了本地服务器。

[![在此处输入图像描述][1]][1]

我想连接到第三方服务的 api。我正在使用以下脚本:

class Auth {
public $url = "https://xxxxxxxxxxxxxxxxx";
public $credentials = [
    'user_name' => 'xxxxxxxxxxxx',
    'user_pass' => 'xxxxxxxxxxxx',
    'product_code' => 'xxx'
    ];

    function moveaway () {
        $access = json_encode($credentials);
        $getting = curl_init($url);
        curl_setopt($getting, CURLOPT_POST, 1);
        curl_setopt($getting, CURLOPT_POSTFIELDS, $access);
        curl_setopt($getting, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($getting, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($getting, CURLOPT_HEADER, false);
        $output = curl_exec($getting);
        curl_close($getting);
        echo $output;
    }
}

由于某种原因,此代码未连接到 api。控制台中没有服务器响应,但也没有错误:

[![在此处输入图像描述][2]][2]

请告诉我,我做错了什么!?

php
  • 2 个回答
  • 10 Views
Martin Hope
Valentin
Asked: 2021-10-30 22:38:18 +0000 UTC

PHP:如何解决2020年PHPWORD库中俄语编码的问题?

  • 0

同事!

我解析 Yandex XML 输出并将结果放入 Word docx 文件中。我以这种方式使用 PHPWORD 库执行此操作:

$section->addText($result);
       $objWriter->save('helloWorld.docx');

某些内容已写入生成的 helloWorld.docx 文件,但 Word 不想打开它。

在此处输入图像描述

如果我尝试用记事本打开文件,会显示文本,但以裂缝的形式

在此处输入图像描述

所有数据在浏览器中正常显示:

在此处输入图像描述

我怀疑问题出在编码上,但我不明白在 PHPWORD 库中编辑什么。-phpword.html ),我什至没有这些文件,因为我刚刚安装了库。也许有人遇到最近有类似的问题吗?我将不胜感激任何建议和帮助...

PS 如果您在 Word 中打开文件时显示的消息中展开详细信息,则会显示 xml 解析错误

php
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5