Navigation Menu

Skip to content

Commit

Permalink
Fix PDO-related errors on certain PHP versions
Browse files Browse the repository at this point in the history
* Remove literal question marks from query
* Set attribute PDO::ATTR_EMULATE_PREPARES to fix General Error 2050

This fixes two errors that occurred on my particular software stack, which includes PHP 5.2.6 and MySQL 5.0.67 running on Solaris 5.11:

* `SQLSTATE[HY000]: General error: 2050` (this occurs on the Capture Data page); fixed by setting `PDO::ATTR_EMULATE_PREPARES`. See also [this discussion thread](https://groups.google.com/forum/#!topic/thinkupapp/RbkAOOQ1Yjg/discussion).
* Failing query on the Tweets tab due to a PDO bug (maybe [this one](https://bugs.php.net/bug.php?id=44251)?) in which question marks occurring in string literals are misparsed as positional parameters; fixed by replacing the offending strings with named parameters.
Closes #1357
  • Loading branch information
dwineman authored and ginatrapani committed Jul 18, 2012
1 parent 5864286 commit 6ed1e29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions webapp/_lib/model/class.PDODAO.php
Expand Up @@ -116,6 +116,7 @@ public final function connect(){
$this->config->getValue('db_password')
);
self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$PDO->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
// if THINKUP_CFG var 'set_pdo_charset' is set to true, set the connection charset to utf8
if ($this->config->getValue('set_pdo_charset')) {
self::$PDO->exec('SET CHARACTER SET utf8');
Expand Down
4 changes: 3 additions & 1 deletion webapp/_lib/model/class.PostMySQLDAO.php
Expand Up @@ -870,12 +870,14 @@ public function getAllQuestionPosts($author_id, $network, $count, $page=1, $orde
$q .= "FROM #prefix#posts p ";
$q .= "WHERE p.author_user_id = :author_id AND p.network=:network ";
$q .= "AND (in_reply_to_post_id IS null OR in_reply_to_post_id = 0) $protected) AS p ";
$q .= "WHERE post_text RLIKE '\\\\?$' OR post_text like '%? %' ";
$q .= "WHERE post_text RLIKE :format1 OR post_text like :format2 ";
$q .= "ORDER BY " . $order_by. ' ' . $direction . ' ';
$q .= "LIMIT :start_on_record, :limit";
$vars = array(
':author_id'=>(string)$author_id,
':network'=>$network,
':format1'=>"\\?$",
':format2'=>"%\\? %",
':limit'=>(int)$count,
':start_on_record'=>(int)$start_on_record
);
Expand Down

0 comments on commit 6ed1e29

Please sign in to comment.