Home  >  Article  >  Backend Development  >  Problems using thinkphp and php-preg_replace, chain query

Problems using thinkphp and php-preg_replace, chain query

WBOY
WBOYOriginal
2016-08-08 09:21:00997browse

This article talks about the problems encountered when using thinkphp:

1. About chain query

          $post_db = D('Post');

$total=

$

total

->where($where1); ; $list=$total->order($order)->limit($limit)->select();

$count=$total-> ;count();At this time we discovered that the value of $count is not the quantity we found, but the total amount, and the expression $total=$

total ->where($where1); has the same effect as $

total->where($where1);, the value of $total will change. If we When you need to query the total number, you can only query it again. This is a very inhumane function in thinkphp;

2. PHP’s native function: preg_replace()

Requirement: I want to modify a specific value in the text through preg_replace() The initial use is as follows: (When backing up SQL, modify the starting value of the auto-increment. Why is there such a need? This involves backing up the log file and backing up in batches when backing up the database. At this time, the log has been increasing, resulting in the auto-increment value. Mismatch, there is a problem when restoring data) Preg_replace('/AUTO_INCREMENT=(d+)/', 'AUTO_INCREMENT='."$1" + 2, $sql);We found that it will be replaced with AUTO_INCREMENT= 2 And $ 1 is not recognized, and use 'auto_increment ='. "$ 1" can be identified alone. There will be problems with the use of variables. I didn’t check the specific reasons. My solution is: if(preg_match('/AUTO_INCREMENT=(d+)/',$sql,$matches) ){

                                                                                                                                     place('/AUTO_INCREMENT=(d+)/', 'AUTO_INCREMENT= '.$auto_int_start, $sql);

That is, calculate it in advance and then replace it. Let’s look at the specific reason later. If any students know the principle, you can also leave a message to tell me, 3Q!

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the problems in using thinkphp and php - preg_replace, chain query, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:AVS30 program analysis 1Next article:AVS30 program analysis 1