为毛PDO查询过程会导致服务器断开?
今天帮人改个程序,测试一切正常后,发过去,在服务器上出现问题,访问某个页面的时候就会出现页面打不开的提示,让检查网络,貌似是服务器断开了连接。
$sql = "SELECT client_id, expires, scope FROM tokens WHERE oauth_token = :oauth_token";<br /> $stmt = $this->db->prepare($sql);<br /> $stmt->bindParam(":oauth_token", $oauth_token, PDO::PARAM_STR);<br /> $stmt->execute();<br /><br /> $result = $stmt->fetch(PDO::FETCH_ASSOC);<br />
跟踪了半天,发现执行到$stmt->execute();的时候就会出现这样的问题
而奇怪的是,同个页面另一个函数却正常:
$sql = "SELECT code, client_id, redirect_uri, expires, scope FROM auth_codes WHERE code = :code";<br /> $stmt = $this->db->prepare($sql);<br /> $stmt->bindParam(":code", $code, PDO::PARAM_STR);<br /> $stmt->execute();<br />
经过调试,参数里的数据没一点问题,改成Mysql驱动获取数据就一切正常,所以数据是没问题的。会是什么问题呢?有人遇到过这样的问题吗?
------解决方案--------------------
信息太少,不好判断。
打开错误提示没有,有不有错误信息。
------解决方案--------------------
检查数据库连接
参考:http://www.php.net/manual/en/pdo.error-handling.php
------解决方案--------------------
出错原因是,select中没有oauth_token字段。
$sql = "SELECT client_id, expires, scope FROM tokens WHERE oauth_token = :oauth_token";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(":oauth_token", $oauth_token, PDO::PARAM_STR);
$sql = "SELECT code, client_id, redirect_uri, expires, scope FROM auth_codes WHERE code = :code";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(":code", $code, PDO::PARAM_STR);
------解决方案--------------------
你总是得贴出错误信息的!
另外,如果你的 php 版本低于 5.3 的话,建议还是不要用 PDO(总是有些莫名其妙的错误的)
------解决方案--------------------
贴全代码,肯定有错误。
------解决方案--------------------
SELECT client_id, expires, scope FROM tokens WHERE oauth_token = :oauth_token
直接拿sql放到mysql编辑器执行试试。
------解决方案--------------------
这不是查看phpinfo()就可以看得到?
------解决方案--------------------
检查代码里有没有$this->db=NULL;
是不是清空了?
------解决方案--------------------
你有客户端吧,客户端总会给你打印出一些东西的,例如
你访问了你的a.php 这个是操作pdo的,你在服务器上的apache/nginx查看不到所有的log?如果看不到那你就看看客户端上服务器response的http code是什么 message是什么,总有办法的。
PDO 我碰见过如果用长连接 会导致一些网页直接挂掉。
------解决方案--------------------
我今天也遇到了同样的问题。。PDO执行select查询导致apache直接断开,查询了PHP log和apche log都没有错误反馈。。但是执行UPDATE/INSERT没有问题,再测试发现执行select a from table可以,但是select a,b from table就立马挂掉,不知道什么原因。

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.


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

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

Hot Article

Hot Tools

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

Notepad++7.3.1
Easy-to-use and free code editor
