pdo

mySQL auto increment problem: Duplicate entry '4294967295' for key 1

耗尽温柔 提交于 2019-12-31 04:23:49
问题 I have a table of emails. The last record in there for an auto increment id is 3780, which is a legit record. Any new record I now insert is being inserted right there. However, in my logs I have the occasional: Query FAIL: INSERT INTO mail.messages (timestamp_queue) VALUES (:time); Array ( [0] => 23000 [1] => 1062 [2] => Duplicate entry '4294967295' for key 1 ) Somehow, the autoincrement jumped up to the INT max of 4294967295 Why on god's green earth would this get jumped up so high? I have

PDO bindParam not allowing statement to return results

青春壹個敷衍的年華 提交于 2019-12-31 04:22:05
问题 I have a pdo statement to select rows and return them in an array. I am using pagination to display 12 results per page. If I directly input LIMIT 12, 12 , instead of LIMIT ?, ? the statement works correctly. What am I doing wrong with the bindParam for both variables? Both variables contain the correct data. Heres the function I'm using: // Retrieve active posts function retrieve_active_posts(){ //test the connection try{ //connect to the database $dbh = new PDO("mysql:host=db2940.oneandone

What is the best way to check if something exists with PDO [duplicate]

烈酒焚心 提交于 2019-12-31 03:30:28
问题 This question already has answers here : Row count with PDO (22 answers) Closed 2 years ago . Some one told me rowCount not safe so I like to ask it here, I have 2 examples and like to know what is the safest and nice way to check if something exists? $sql = "SELECT count(*) FROM users WHERE username = 'administrator'"; $result = $db->prepare($sql); $result->execute(); echo $result->fetchColumn() ? 'true' : 'false'; or $sql = "SELECT username FROM users WHERE username = ?"; $result = $db-

PDO query is always returning 1 or true

旧城冷巷雨未停 提交于 2019-12-31 02:44:51
问题 I am trying to check if a row exists before I delete it. The row in my table doesn't exist but it always returns 1 : $orders = $this->db->prepare("SELECT * FROM orders WHERE id=? AND user=?"); $check = $orders->execute(array($message,$this->model->checkapi($data,$message))); echo $check; if($check){ $deleteorder = $this->db->prepare("DELETE FROM orders WHERE id=? AND user=?"); $deleteorder->execute(array($message,$this->model->checkapi($data,$message))); array_push($result, array('success' =>

Get MySQL Server Version with PDO

a 夏天 提交于 2019-12-31 02:40:20
问题 I'm building out an app in Laravel 5 and I need to ensure that one of my tables will be able to perform FULLTEXT searches. I'd like to detect the MySQL version number(ensuring it's at least 5.6.10 or above) so that I can switch the engine to MyISAM in my migration file for a given table, if that condition fails. I can't seem to find any docs on how to access the MySQL server info using PDO, which is what Laravel uses out of the box. Any help is appreciated. 回答1: Why not just run select

PHP created Excel Sheet creates errors upon opening

岁酱吖の 提交于 2019-12-31 01:27:10
问题 So, my current code works 100%, the file is made and it is opened in excel. But upon opening, there are a few errors one must click through in order to open the file. They are as follows: The file format and extension of 'address-book.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway? Then: Excel has detected that 'address-book.xls is a SYLK file, but cannot load it. Either the file has errors or it is not a SYLK

Is there a function for closing a mysql prepared statement with PDO?

你离开我真会死。 提交于 2019-12-30 23:38:07
问题 In mysqli prepared statements there ismysqli_stmt::close() (Closes a prepared statement): $stmt->close(); I have searched php.net and the web and cannot find an alternative for PDO. Is this possible? And what are the benefits of using it at the end of each of your scripts? I understand that, $connection = null; closes the connection to mysql, but what about closing the query? 回答1: To free the result set you can apply basic PHP way. If you are returning the results with PDOStatement::fetchAll(

PDO fetch returns nothing [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-30 23:35:29
问题 This question already has answers here : PHP PDOException: “SQLSTATE[HY093]: Invalid parameter number” (4 answers) Closed 5 years ago . I've encountered a little problem. I have the following code: $query = $db->prepare('(SELECT last_visit, last_ip FROM user_log WHERE user_id = :id) UNION (SELECT time AS last_visit, packet_hex AS last_ip FROM crack_log WHERE target_id = :id) ORDER BY last_visit DESC LIMIT 0,10;'); $query->execute(array(':id'=> $_SESSION['id'])); $log = $query->fetchAll(PDO:

PDO fetch returns nothing [duplicate]

你说的曾经没有我的故事 提交于 2019-12-30 23:35:22
问题 This question already has answers here : PHP PDOException: “SQLSTATE[HY093]: Invalid parameter number” (4 answers) Closed 5 years ago . I've encountered a little problem. I have the following code: $query = $db->prepare('(SELECT last_visit, last_ip FROM user_log WHERE user_id = :id) UNION (SELECT time AS last_visit, packet_hex AS last_ip FROM crack_log WHERE target_id = :id) ORDER BY last_visit DESC LIMIT 0,10;'); $query->execute(array(':id'=> $_SESSION['id'])); $log = $query->fetchAll(PDO:

PDO “Uncaught exception 'PDOException' .. Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll().”

一世执手 提交于 2019-12-30 18:09:23
问题 I know this question has been asked many times, but I've read the answers to many of the questions and still cannot understand why I am receiving this error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE