WordPress + Sqlite と Simple Tags で不具合

このブログのタグはWordPressのプラグイン Simple Tags を使っていて、
デフォルトの設定で使っているぶんには特に問題がありませんでした。

が、、、関連投稿を自動で表示するように設定を変えたところ下のようなエラーが発生。

Warning: mysql_get_server_info() [function.mysql-get-server-info]: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) in …

Warning: mysql_get_server_info() [function.mysql-get-server-info]: A link to the server could not be established in …

エラーが発生していた

\wp-content\plugins\simple-tags\2.7\simple-tags.client.php

を見てみる。

			// Group Concat only for MySQL > 4.1 and check if post_relatedtags is used by xformat...
			$select_gp_concat = '';
			if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') && ( strpos($xformat,'%post_relatedtags%') || $min_shared > 1 ) ) {
				$select_gp_concat = ', GROUP_CONCAT(tt.term_id) as terms_id';
			} else {
				$xformat = str_replace('%post_relatedtags%', '', $xformat); // Group Concat only for MySQL > 4.1, remove related tags
			}

これか。。。

version_compare(mysql_get_server_info(), ‘4.1.0’, ‘>=’)

MySQLのバージョンを求められてもウチのはSqliteなので・・・・
比較演算子の && ごとゴッソリ消してやる。

			// Group Concat only for MySQL > 4.1 and check if post_relatedtags is used by xformat...
			$select_gp_concat = '';
			if ( ( strpos($xformat,'%post_relatedtags%') || $min_shared > 1 ) ) {
				$select_gp_concat = ', GROUP_CONCAT(tt.term_id) as terms_id';
			} else {
				$xformat = str_replace('%post_relatedtags%', '', $xformat); // Group Concat only for MySQL > 4.1, remove related tags
			}

ローカルのXAMPPで動作を確認してFTPでアップ。

あれ?

  • ()
  • ()
  • ()
  • ()

文字がでてこない。。。
XAMPPだと問題ないのに。

var_dump() で中を見てみると、 $result[‘p.post_title’] な風に格納されてる。
ソースをみるとSQL文はこんな感じ。

			$results = $wpdb->get_results("
				SELECT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) AS counter {$select_excerpt} {$select_gp_concat}
				FROM {$wpdb->posts} AS p

テーブル名の p. が原因っぽいので、AS を使って無理やり列名をつけてみたところうまくいきました。

			$results = $wpdb->get_results("
				SELECT p.post_title AS post_title, p.comment_count AS comment_count, p.post_date AS post_date, p.ID AS ID, COUNT(tr.object_id) AS counter {$select_excerpt} {$select_gp_concat}
				FROM {$wpdb->posts} AS p

PHP とか Sqlite のバージョンの差が問題なのかな?
ちなみに環境は下の通りです。

  • PHP5.3.0 + WordPress 2.8.4 (XAMPP 1.7.2)
  • PHP5.2.9 + WordPress 2.7.1

上がローカルで下がサイト側。

根本の原因はわからなかったけど動いたので良しとするが、
別の設定変えたらまた何かエラーが出てきそうだな・・・

スポンサーリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

スポンサーリンク