Category Archives: PHP

TP5 fuzzy Chinese characters error [How to Solve]

When using TP5 to fuzzy query Chinese characters, sometimes some Chinese characters will report errors, which are placeholder errors, so modify the paging style;

Modify the bootrapthink.php file

return sprintf(
//                    '<div id="page" class="page_div pagination">%s %s %s<span class=\'totalSize\'> 跳转<input class=\'jump_class jump_page_num\' οnkeyup="this.value=this.value.replace(/\D/, \'\');" type=\'text\' value=\'\'>页 </span><a href=\'javascript:void(0);\' οnclick=\'jumpPage(this);\' data-href="'.$base_url.'" class=\'jump_btn\' style=\'color: #18a689;border: 1px solid #18a689!important;margin-left:0px;\'>确定</a><span class="totalPages"> 共<span>'.$this->lastPage.'</span>页 </span><span class="totalSize"> 共<span>'.$this->total.'</span>条记录 </span></div>',
//                    $this->getPreviousButton(),
//                    $this->getLinks(),
//                    $this->getNextButton()

Sometimes you will find something wrong with his placeholder

Change to:

return '<div id="page" class="page_div pagination">'.$this->getPreviousButton().' '.$this->getLinks().' '.$this->getNextButton().'<span class=\'totalSize\'> 跳转<input class=\'jump_class jump_page_num\' οnkeyup="this.value=this.value.replace(/\D/, \'\');" type=\'text\' value=\'\'>页 </span><a href=\'javascript:void(0);\' οnclick=\'jumpPage(this);\' data-href="'.$base_url.'" class=\'jump_btn\' style=\'color: #18a689;border: 1px solid #18a689!important;margin-left:0px;\'>确定</a><span class="totalPages"> 共<span>'.$this->lastPage.'</span>页 </span><span class="totalSize"> 共<span>'.$this->total.'</span>条记录 </span></div>';

With specific analysis of the situation, finally, I wish you all a smooth work!

[Solved] WordPress Upgrade PHP 5.6 to 7.x Fatal error: Uncaught Error: Call to undefined function mysql_connect()

Error reporting when upgrading PHP version 5.6 to 7. X under WordPress (resolved)

Cause of event:

When using WordPress, the theme needs to be upgraded. The PHP version required for viewing the theme is 7.1+

When the website is not backed up, the PHP version is changed to 7.2, which directly leads to the website error

Fatal error: Uncaught Error: Call to undefined function mysql_ connect()

Check many online tutorials, which are MySQL in wp-db.php_Change connect() to mysqli_Connect(), no result

At first, I thought that the database reported an error, checked the database in detail, wrote checkdb.php, locally connected to the database, and checked that the database server was running well

Solution:

Set define ('wp_use_ext_mysql ', true) in wp-config.php delete

error explanation:

define('WP_USE_EXT_MYSQL',true);

define(‘WP_USE_EXT_MYSQL’, true); Force WP to use MySQL by default instead of MySQL Li
so please delete this line and the problem should be solved.

Otherwise, you can check nd in the PHP 7 configuration_Mysqli extension, and disable mysqli extension – > Select the PHP version.

Error while injecting dependencies into App\Controller\IndexController: No entry or class found for

An error occurs when a service consumer class is manually created for the hyperf 2.2.0 microservice.

In the documentation on the official website, when manually creating a consumer class, its recommended configuration of services.php is as follows.

<?php
return [
    'consumers' => [
        [
            'name' => 'CalculatorService',
            'registry' => [
                'protocol' => 'consul',
                'address' => 'http://127.0.0.1:8500',
            ],
            'nodes' => [
                ['host' => '127.0.0.1', 'port' => 9504],
            ],
        ]
    ],
];

Later, I saw the video on the official website jsonrpc. The recommendation in the video is as follows.

<?php
return [
    'consumers' => [
        [
            'name' => 'CalculatorService',
            'nodes' => [
                ['host' => '127.0.0.1', 'port' => 9504],
            ],
        ]
    ],
];

I wonder if the above writing is only applicable to the 1. X.x era?When I upgrade to 2.2.0, it is reported above

[ERROR] Error while injecting dependencies into App\Controller\IndexController: No entry or class found for ‘App\Rpc\CalculatorServiceInterface'[101]

After tossing for a long time, I found that there are few services.php configurations

    'service' => \App\Rpc\CalculatorServiceInterface::class,

So, don’t lose service. The complete services.php is like this

return [
    'consumers' => [
        [
            // name needs to be the same as the name attribute of the service provider
            'name' => 'CalculatorService',
            // service interface name, optional, default value is equal to the value configured by name, if name is defined directly as an interface class then this line can be ignored, if name is a string then you need to configure service to correspond to the interface class
            'service' => \App\Rpc\CalculatorServiceInterface::class,
            // corresponding to the container object ID, optional, default value is equal to the service configuration value, used to define the dependency injection key
            'id' => \App\Rpc\CalculatorServiceInterface::class,
            // Service protocol of the service provider, optional, default value is jsonrpc-http
            // optional jsonrpc-http jsonrpc jsonrpc-tcp-length-check
            'protocol' => 'jsonrpc-http',
            // load balancing algorithm, optional, default value is random
// 'load_balancer' => 'random',
            // which service center this consumer will get the node information from, if not configured it will not get the node information from the service center
// 'registry' => [
// 'protocol' => 'consul',
// 'address' => 'http://127.0.0.1:8500',
// ],
            // If the above registry configuration is not specified, i.e., the node is consumed directly for the specified node, and the node information of the service provider is configured with the following nodes parameter
            'nodes' => [
                ['host' => '127.0.0.1', 'port' => 9504],
            ],
        ]
    ],
];

Run later and run through

[Solved] Fatal error: Class ‘think\Container‘ not found & [InvalidArgumentException] Could not find package

Fatal error: class’ think \ container ‘not found. This error means that the ThinkPHP core framework warehouse is not a branch of version 5.1, so the container of version 5.1 is not found;

The solution is to execute the following command on the terminal terminal of the IDE:

composer create-project topthink/think tp 5.1.35

Starting from tp5.1, the official website no longer provides a full version download, but can only be installed through the composer method.

[invalidargumentexception] could not find package. This error means that the installation package of the corresponding version is not found. The problem in the figure below is that the version number behind 5.1 is missing. It is correct after supplement as shown in the figure above.

  The program operation after correct input is as follows:

[Solved] getObject: FAILED RequestCoreException: cURL resource: Resource id #78; cURL error: SSL certificate

Reason:

The reason for this problem is that curl.cainfo is not configured, which is located in php.ini.

Solution:

Since the reasons for the errors are stated, it is much easier to solve them, as follows:

1. Download cacert

Download address: https://curl.haxx.se/ca/cacert.pem

2. Modify php.ini and restart

curl.cainfo="real_path/cacert.pem"

matters needing attention:

Needs to be turned on php_curl、php_openSSL extension;

PHP file download, download failed, nginx open() nginx / fastcgi_ temp/2/10/0000000102“ failed (13: Permission denied)

summary

The file download failed when testing the project

Check the problem

After investigation, it is found that nginx gives error information
open() "/ home/server/nginx/fastcgi_ Temp/2/10/0000000102 "failed (13: permission denied) while reading upstream
nginx prompts us that we do not have permission to operate

and then we enter the directory /home/server/nginx to check fastcgi_ Temp file owner, our name is the root user of root group

we will check the user group and user name of nginx worker again

ps -ef | grep nginx
# We can see that the worker process of nginx is the www user
root 80246 1 0 10:37 ?       00:00:00 nginx: master process /home/server/nginx/sbin/nginx
www 80247 80246 0 10:37 ?       00:00:00 nginx: worker process
root 82877 82840 0 13:56 pts/7 00:00:00 grep --color=auto nginx
# View the group that the www user is in, and the members of the group
groups www
# Ours is the www user of the www user group
www:www

solve the problem

When we download, the nginx worker process is sending the fastcgi_ Temp does not have permission to write to the cache
so we just need to give fastcgi_ The start-up user with the permission of nginx to modify the temp directory WWW: www

chown -R www:www fastcgi_temp/

Undefined index: name error in composer [How to Solve]

I made this mistake when:

Laravel version 5.8, need to introduce tcpdf, in the run

composer require tecnickcom/tcpdf

I found two answers, both of which were caused by the composer upgrade, but I don’t remember that I was promoted. I learned from one of the methods and successfully introduced the tcpdf extension. Now I integrate the two methods:

1. Change the source code

Positioning error:

vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php

122 line prompt does not have the key name, according to the code prompt to find

/vendor/laravel/framework/src/Illuminate/Support/Collection.php

Of   Mapwithkeys method. Add a compatible method to cover the original method

 public function mapWithKeys(callable $callback)
    {
        $result = [];
        $item = $this->items;
        if(isset($item['packages'])){
            $item = $item['packages'];
        }
        foreach ($item as $key => $value) {
            $assoc = $callback($value, $key);
 
            foreach ($assoc as $mapKey => $mapValue) {
                $result[$mapKey] = $mapValue;
            }
        }
 
        return new static($result);
    }

2. Composer level

# composer Downgrade (if you can't downgrade, you can try to run with root privileges)
composer self-update --1
 
# Re-install and It's Done!!!
composer install 

The above two methods are effective

[Solved] Git error: You have not concluded your merge (MERGE_HEAD exists)

Enter the root directory of the website

Solution 1: keep the local changes and stop merging – & gt; Re merge – & gt; Pull again

$:git merge --abort
$:git reset --merge
$:git pull

Solution 2: discard the local code, and the remote version will cover the local version (be careful)

$:git fetch --all           //Repulling
$:git reset --hard origin/master //git reset --hard reverts master back to origin/master and ignores all new commits
$:git fetch

[Solved] has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: No

Has been blocked by CORS policy: response to preflight request doesn’t pass access control check: no ‘access control allow origin’ header is present on the requested resource.
seeing this error in the webpage, I know that it must be a cross domain problem of Ajax requests.
there are two solutions to this problem, as you should know after reading my article, Before I sent the front-end solution, I don’t know how to flip through my article list
today we talk about the server-side solution
add this code before the JSON data to be returned:


// Specify to allow access to other domains
header('Access-Control-Allow-Origin:*');
// Response type
header('Access-Control-Allow-Methods:POST');
// response header settings
header('Access-Control-Allow-Headers:x-requested-with,content-type');

Here is the PHP code, you can also change it to the corresponding java code.

[Solved] PhpSpreadsheet Error: Invalid cell coordinate [1

When TP5 uses phpspreadsheet, if the number of columns exceeds 26, it will report an error. The specific solutions are as follows: it is easy to use by personal test

//Write to the table header section to read
  // Set the table header
  // $head formatted as ['Name', 'Phone', 'Contact']
        $colum = 'A';
        foreach ($head as $v) {
            $sheet->setCellValue($colum . '1', $v);
            $sheet->getColumnDimension($colum)->setWidth(20);
            $colum++;
        }
        //Write content to read
          $column = 2;
        foreach ($data as $key => $rows) {
            $span = 'A';
            // Column Write
            foreach ($rows as $keyName => $value) {
                $sheet->setCellValue($span . $column, $value);
                $span++;
            }
            $column++;
        }