﻿{"id":786,"date":"2011-12-17T22:00:40","date_gmt":"2011-12-17T14:00:40","guid":{"rendered":"http:\/\/notes.zerobox.org\/?p=786"},"modified":"2011-12-17T22:06:35","modified_gmt":"2011-12-17T14:06:35","slug":"php%e9%98%b2%e6%b3%a8%e5%85%a5","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/786.html","title":{"rendered":"php\u9632\u6ce8\u5165"},"content":{"rendered":"<p>function prepare_query($sql, $params=null)<\/p>\n<p>{<\/p>\n<p>$sql_block = explode(&#8220;?&#8221;, $sql);<\/p>\n<p>$sp_size = sizeof($sql_block) &#8211; 1;<\/p>\n<p>$param_size = sizeof($params);<\/p>\n<p>&nbsp;<\/p>\n<p>if ( $sp_size == 0 &amp;&amp; $params == null)<\/p>\n<p>return $sql;<\/p>\n<p>&nbsp;<\/p>\n<p>if ( ($sp_size &lt; 1) || ($param_size &lt; 1) || ($sp_size != $param_size) )<\/p>\n<p>return &#8220;&#8221;;<\/p>\n<p>&nbsp;<\/p>\n<p>if ($param_size == 1)<\/p>\n<p>{<\/p>\n<p>if ( gettype($params) == &#8216;string&#8217;)<\/p>\n<p>{<\/p>\n<p>$result = str_replace(&#8216;?&#8217;, &#8220;&#8216;&#8221;.$params.&#8221;&#8216;&#8221;, $sql);<\/p>\n<p>}<\/p>\n<p>else if ( gettype($params) == &#8216;integer&#8217;)<\/p>\n<p>{<\/p>\n<p>$result = str_replace(&#8216;?&#8217;, $params, $sql);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else if ($param_size &gt; 1)<\/p>\n<p>{<\/p>\n<p>for ($i = 0; $i &lt; sizeof($params); $i++)<\/p>\n<p>{<\/p>\n<p>if ( gettype($params[$i]) == &#8216;string&#8217;)<\/p>\n<p>$sql_block[$i] .= &#8220;&#8216;&#8221;.$params[$i].&#8221;&#8216;&#8221;;<\/p>\n<p>else if ( gettype($params[$i]) == &#8216;integer&#8217;)<\/p>\n<p>$sql_block[$i] .= $params[$i];<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>$result = &#8220;&#8221;;<\/p>\n<p>for ($i = 0; $i &lt; $param_size; $i++)<\/p>\n<p>{<\/p>\n<p>$result .= $sql_block[$i];<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>return $result;<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>function prepare_query($sql, $params=nul &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/786.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[56],"class_list":["post-786","post","type-post","status-publish","format-standard","hentry","tag-php"],"views":1036,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=786"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/786\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}