add.inc.php:
<?phpif(!defined('IN_DISCUZ')) { exit('Access Denied');}$q1 = $_REQUEST['q1']; $addtime = time(); $insert_array = array( 'baankid'=>$q1, ); $cone = DB::insert('pre_xyk',$insert_array);?>
echo $q1; 这样是有输出的,但是怎么写不进数据的?
DZ的插件是怎么操作数据库的?
add.inc.php怎么写才正确?先谢谢了!
回复讨论(解决方案)
require './source/class/class_core.php';C::app()->init();$insert_array = array( 'classname'=>'test', 'uid'=>1, 'dateline'=>time());if(DB::insert('home_class',$insert_array)){ echo 'ok';}/*ok*/
插入不成功discuz应该报错,怎么没有错误提示?
猜测:
1、class_core.php没有引入,并且没有初始化,不能使用DB调用
2、pre_xyk是表全名,默认是不要pre_前缀(若设置有)
<?phprequire './source/class/class_core.php';C::app()->init(); $insert_array = array( 'baankid'=>1,);if(DB::insert('xyk',$insert_array)){ echo 'ok';}?>
就算这样执行也没有写入,
插件块那里用不用定义add.inc.php?
不成功总有提示吧,就是错误报告
你单独访问这个页面试试,成不成功
单独访问这个页面,没有任何输出,一片空白
include '../source/class/class_core.php';$discuz = & discuz_core::instance();$discuz->init();print_r($_G);
这样是有变量输出的,为什么:
include '../source/class/class_core.php';
../就有输出,./没有输出呢?
require '../../../source/class/class_core.php';//引入系统核心文件$discuz = & discuz_core::instance();//以下代码为创建及初始化对象$discuz->cachelist = $cachelist;$discuz->init();//以上是调用discuz公共执行类等核心代码//写入数据库$arr=array();$arr['userid'] = $userid;$count1=DB::insert('xyk',$arr);
这样已经能写入了,有点不明白,为什么这样就得:
require '../../../source/class/class_core.php';//引入系统核心文件
这样就不得:
require './source/class/class_core.php';//引入系统核心文件
路径没设好?
..是上一级目录开始查找
.是当前目录开始查找
嗯 非常感谢jam00的耐心解答,谢谢!
但是我见所有的插件都不会用 ../../../
都是 ./也能正常
目录层数都一样,为什么我的就必需用 ../../../ ?用绝对路径为什么也不得?

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment