Home PHP Framework ThinkPHP What to do if thinkphp fails to be added to sql

What to do if thinkphp fails to be added to sql

Aug 22, 2019 pm 03:37 PM
sql thinkphp fail Add to

What to do if thinkphp fails to be added to sql

What should I do if ThinkPHP fails to add data to the database?

Generally, several aspects will be checked first:

· Check whether the controller or Model name is incorrect.

·Check whether the data to be inserted is empty or missing parameters.

·Check the data table name and field name (most of the time, the field name is wrong).

If you check repeatedly and find that the data to be inserted is normal and the field names and table names are correct, you may wonder if the program has lost its temper and you need to quit and start again? Restart? Try again? After struggling like this for a long time, you find that nothing has changed. At this time, you should consider other situations.

Related recommendations: "ThinkPHP Tutorial"

fields field caching

When using the ThinkPHP framework for development, there are data structures When making changes, when calling the M()->add() method to insert data, the insertion always fails and some field contents are lost. So if you print out the model object and look carefully, you will find that the lost fields are all newly added fields. You will think of cache, so you can clear all the cache files in the runtime and insert it normally.

TP If the field cache setting [TMPL_CACHE_ON => false] is not turned off in the configuration file, this configuration means whether to turn on the template compilation cache. If set to false, it will be recompiled every time. The default is turned on. , as soon as it is run, it will cache the data field information to the ~Runtime/Data/_files folder, and store it in the file as an array. Just close it if you don’t need it.

·debug.php

  return  array(
     'LOG_RECORD'=>  true,  // 进行日志记录
     'LOG_EXCEPTION_RECORD'=>  true,    // 是否记录异常信息日志
     'LOG_LEVEL'=>  'EMERG,ALERT,CRIT,ERR,WARN,NOTIC,INFO,DEBUG,SQL',  // 允许记录的日志级别
     'DB_FIELDS_CACHE'=>  false, // 字段缓存信息
      'DB_DEBUG'=>  true, // 开启调试模式 记录SQL日志
      'TMPL_CACHE_ON'=>  false,        // 是否开启模板编译缓存,设为false则每次都会重新编译
      'TMPL_STRIP_SPACE'=>  false,       // 是否去除模板文件里面的html空格与换行
      'SHOW_ERROR_MSG'=>  true,    // 显示错误信息
      'URL_CASE_INSENSITIVE'=>  false,  // URL区分大小写
   );
Copy after login

·convention.php

  // 布局设置
  'TMPL_ENGINE_TYPE'      =>  'Think',     // 默认模板引擎 以下设置仅对使用Think模板引擎有效
  'TMPL_CACHFILE_SUFFIX'  =>  '.php',      // 默认模板缓存后缀
  'TMPL_DENY_FUNC_LIST'   =>  'echo,exit',    // 模板引擎禁用函数
  'TMPL_DENY_PHP'         =>  false, // 默认模板引擎是否禁用PHP原生代码
  'TMPL_L_DELIM'          =>  '{',            // 模板引擎普通标签开始标记
  'TMPL_R_DELIM'          =>  '}',            // 模板引擎普通标签结束标记
  'TMPL_VAR_IDENTIFY'     =>  'array',     // 模板变量识别。留空自动判断,参数为'obj'则表示对象
  'TMPL_STRIP_SPACE'      =>  true,       // 是否去除模板文件里面的html空格与换行
  'TMPL_CACHE_ON'         =>  true,        // 是否开启模板编译缓存,设为false则每次都会重新编译
  'TMPL_CACHE_PREFIX'     =>  '',         // 模板缓存前缀标识,可以动态改变
  'TMPL_CACHE_TIME'       =>  0,         // 模板缓存有效期 0 为永久,(以数字为值,单位:秒)
  'TMPL_LAYOUT_ITEM'      =>  '{__CONTENT__}', // 布局模板的内容替换标识
  'LAYOUT_ON'             =>  false, // 是否启用布局
  'LAYOUT_NAME'           =>  'layout', // 当前布局名称 默认为layout
Copy after login

· System behavior extension: template parsing, check whether the cache file is valid, if it is invalid, it needs to be recompiled, ParseTemplateBehavior.class.php

  protected function checkCache($tmplTemplateFile,$prefix='') {
  if (!C('TMPL_CACHE_ON')) // 优先对配置设定检测
      return false;
  $tmplCacheFile = C('CACHE_PATH').$prefix.md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX');
  if(!Storage::has($tmplCacheFile)){
      return false;
  }elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile,'mtime')) {
      // 模板文件如果有更新则缓存需要更新
      return false;
  }elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile,'mtime')+C('TMPL_CACHE_TIME')) {
      // 缓存是否在有效期
      return false;
  }
  // 开启布局模板
  if(C('LAYOUT_ON')) {
      $layoutFile  =  THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX');
      if(filemtime($layoutFile) > Storage::get($tmplCacheFile,'mtime')) {
          return false;
      }
  }
  // 缓存有效
  return true;
  }
Copy after login

The above is the detailed content of What to do if thinkphp fails to be added to sql. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Usage of division operation in Oracle SQL Usage of division operation in Oracle SQL Mar 10, 2024 pm 03:06 PM

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Comparison and differences of SQL syntax between Oracle and DB2 Comparison and differences of SQL syntax between Oracle and DB2 Mar 11, 2024 pm 12:09 PM

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

How to add a TV to Mijia How to add a TV to Mijia Mar 25, 2024 pm 05:00 PM

Many users are increasingly favoring the electronic ecosystem of Xiaomi smart home interconnection in modern life. After connecting to the Mijia APP, you can easily control the connected devices with your mobile phone. However, many users still don’t know how to add Mijia to their homes. app, then this tutorial guide will bring you the specific connection methods and steps, hoping to help everyone in need. 1. After downloading Mijia APP, create or log in to Xiaomi account. 2. Adding method: After the new device is powered on, bring the phone close to the device and turn on the Xiaomi TV. Under normal circumstances, a connection prompt will pop up. Select "OK" to enter the device connection process. If no prompt pops up, you can also add the device manually. The method is: after entering the smart home APP, click the 1st button on the lower left

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

See all articles