search
HomeBackend DevelopmentPHP Tutorial如何查看android回传给php-server(依托discuz的接口)参数后执行的sql语句

项目配置描述如下:
服务器端:discuz,正在调试连接android的服务器端接口(用来接收android端发送过来的请求)
客户端:Android4.4

问题流程描述如下:
android端在论坛发帖后,使用httppost封装参数,通过httpclient发送到php端的相关url;在php端执行相关的sql操作,通过mysql_query返回true或者false给android端。

问题描述如下:
现在在android端得到发帖返回的结果是{"result":"post failed"} ,(ˇ?ˇ) 想到可能是php端在执行sql操作时发生了错误,想查看php端执行的sql语句。由于我的php接口是依托于discuz的,如果单独将该接口通过zend studio部署到Apache的htdocs,我试过,没有部署成功,无法接收android端发送的参数

想咨询下大家,
1)有没有可能将此接口部署到apache以接收android端的数据(win7,apache,mysql,php5.25,zend studio 10.0)
2)如果没有,怎么调试android端传送给php服务端的参数;现在主要想查看回传给php服务端后,执行的sql语句。

先谢谢大家了


回复讨论(解决方案)

这个问题刚好我也遇到了,解决办法如下
找到:\source\class\discuz\discuz_error.php,并打开
搜索:show_error($type, $errormsg, $phpmsg = '', $typemsg = '')
在show_error函数下面,用file_put_contents函数将$errormsg打印到一个txt里面

public static function show_error($type, $errormsg, $phpmsg = '', $typemsg = '') {		global $_G;file_put_contents(DISCUZ_ROOT.'./appapi/log.txt',$errormsg.PHP_EOL,FILE_APPEND);		ob_end_clean();		$gzip = getglobal('gzipcompress');		ob_start($gzip ? 'ob_gzhandler' : null);//后面的就不复制了...}

缺点就是,discuz的所有sql错误都会记录在里面,当然一般discuz报的sql错误还是很少的

首先感谢jam00的回答,但我这个论坛是discuzX2的版本,我在 \source\class\class_error.php中进行了您说的相应修改:

function show_error($type, $errormsg, $phpmsg = '') {		global $_G;		file_put_contents('http://192.168.1.101/bbs/android/log.txt',$errormsg.PHP_EOL,FILE_APPEND);		//file_put_contents(DISCUZ_ROOT.'./android/log.txt',$errormsg.PHP_EOL,FILE_APPEND); 		ob_end_clean();		$gzip = getglobal('gzipcompress');		ob_start($gzip ? 'ob_gzhandler' : null);

运行android发帖后,没有在android文件夹中发现log.txt这个文件。
我想补充一点:我的post请求是android直接发给应用接口(该接口可以作为2级目录直接访问)的,然后通过sql处理mysql数据库,再返回给android进行页面呈现;没有和原有的discuz X2进行通信。所以在原有的discuz X项目中设置错误日志估计不能捕捉到这种独立接口的错误。因此才想到要在zend studio10.0中调试接口,获取sql语句。
不管怎样,还是要谢谢jam00的热心解答!

若你想和discuz的数据完美结合,并减少开发时间的话,建议你还是用discuz已有的DB类和方法
我不知道zend 在哪里处理了sql,不过执行sql错误,你可以用mysql_error()获取错误信息,用file_put_contents输出到一个txt里面

把你接口的相关代码亮出来。
没代码怎么解决问题。。。

这个需要看你的接口了,能不能手工单独调试?
如果能,你只需要关心传送的参数

像你这样对发挥数据做了包装的系统,需要对客户端和服务端分开来调试

谢谢大家,尤其谢谢最先提供帮助的jam00,问题已经解决了。通过查看mysql_error,的报错,最后修改了forum_post的一个字段类型。

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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

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 Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor