{"id":18,"date":"2006-05-30T19:03:34","date_gmt":"2006-05-30T10:03:34","guid":{"rendered":"https:\/\/deskplate.net\/blog\/2006\/05\/30\/pear-db-%e6%9b%b4%e6%96%b0\/"},"modified":"2006-05-30T19:03:34","modified_gmt":"2006-05-30T10:03:34","slug":"pear-db-%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/deskplate.net\/blog\/archives\/18","title":{"rendered":"Pear DB \u66f4\u65b0"},"content":{"rendered":"<p>&lt;?php<br \/>\n\/\/===== \u30d1\u30e9\u30e1\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\uff08\u4ee5\u964dCFG_*\u306f\u5f53\u30d5\u30a1\u30a4\u30eb\u306b\u3088\u308a\u8a2d\u5b9a\u3055\u308c\u305f\u5b9a\u6570\uff09<br \/>\nrequire_once (&#8216;include\/param.inc.php&#8217;);<br \/>\nrequire_once (&#8216;include\/pear\/DB.php&#8217;);\t\/\/ \u2605\u2605\u2605<br \/>\n\/\/===== DB\u63a5\u7d9a<br \/>\n$db = DB::connect (&#8220;mysql:\/\/&#8221;.CFG_MYSQL_USERNAME.&#8221;:&#8221;.CFG_MYSQL_PASSWORD.&#8221;@&#8221;.CFG_MYSQL_HOST.&#8221;\/CFG_MYSQL_DBNAME&#8221;);\t\/\/ \u2605\u2605\u2605<br \/>\nif (DB::isError( $db )) {<br \/>\ndie($db->getMessage());<br \/>\n}\t\/\/ \u2605\u2605\u2605<br \/>\n\/\/===== \u6587\u5b57\u5316\u3051\u5bfe\u7b56<br \/>\n$sql = &#8220;SET NAMES utf8&#8221;;<br \/>\n$result = $db->query($sql);\t\/\/ \u2605\u2605\u2605<br \/>\n\/\/===== \u30a4\u30f3\u30b5\u30fc\u30c8\u7528\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf<br \/>\n$tmani_time = &#8220;\u6642\u9593&#8221;;<br \/>\n$tmani_from = &#8220;\u30d5\u30ed\u30e0&#8221;;<br \/>\n$tmani_subject = &#8220;\u6587\u5b57\u5316\u3051\u76f4\u3063\u3066\u308b\u3068\u3044\u3044\u306d&#8221;;<br \/>\n$tmani_body = &#8220;\u304a\u5143\u6c17\u3067\u3059\u304b\uff1f<br \/>how r u?&#8221;;<br \/>\n\/\/===== \u30af\u30a8\u30ea\u30fc\u6587\u306e\u8a2d\u5b9a<br \/>\n$stt=$db->prepare(&#8220;INSERT INTO\t&#8220;.CFG_MYSQL_TABPREFIX.&#8221;posts (<br \/>\npost_mail_from,<br \/>\npost_mail_subject,<br \/>\npost_mail_body)<br \/>\nVALUES (?,?,?)&#8221;);\t\/\/ \u2605\u2605\u2605<br \/>\n\/\/===== \u30af\u30a8\u30ea\u30fc\u6587\u306e\u5b9f\u884c<br \/>\n$res = $db->execute($stt,array($tmani_from,$tmani_subject,$tmani_body));\t\/\/ \u2605\u2605\u2605<br \/>\nif( $db->isError($return) ){<br \/>\n$db->rollback();<br \/>\ndie($res->getMessage());<br \/>\n}<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000$db->commit();<br \/>\n\/\/===== \u7d50\u679c\u8868\u793a<br \/>\n$post_id = mysql_insert_id();<br \/>\n$next_id = $db->nextid($res)\t\/\/ \u2605\u2605\u2605<br \/>\nif($res) {<br \/>\necho &#8220;\u6210\u529f\uff01 \\n res: &#8220;.$res.&#8221; \\n post-id: &#8220;.$post_id.&#8221; \\n next-id: &#8220;.$next_id;\t\/\/ \u2605\u2605\u2605<br \/>\n} else {<br \/>\necho &#8220;\u5931\u6557\u2193 \\n res: &#8220;.$res.&#8221; \\n post-id: &#8220;.$post_id.&#8221; \\n next-id: &#8220;.$next_id;\t\/\/ \u2605\u2605\u2605<br \/>\n}<br \/>\n\/\/===== DB\u30af\u30ed\u30fc\u30ba<br \/>\n$db->disconnect();\t\/\/ \u2605\u2605\u2605<br \/>\n?&gt;<br \/>\n\u3053\u3093\u306a\u98a8\u306b<br \/>\n\u30d7\u30ea\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\uff33\uff31\uff2c\u306e\u5834\u5408\u306f\u3000prepare, excute \u3067\u884c\u3046<br \/>\n\u305d\u3046\u3067\u306a\u3051\u308c\u3070query\u3067\uff2f\uff2b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/\/===== \u30d1\u30e9\u30e1<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}