{"id":45,"date":"2009-07-01T18:30:12","date_gmt":"2009-07-01T18:30:12","guid":{"rendered":"http:\/\/dev001.dl\/yan\/wdp\/?p=45"},"modified":"2026-01-20T05:06:49","modified_gmt":"2026-01-20T05:06:49","slug":"mysql-interface-php","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=45","title":{"rendered":"MySQL interface &#8212; PHP"},"content":{"rendered":"<p><strong>Connect and Close connection to DB<\/strong><\/p>\n<p>$DB_HOST = &#8220;localhost&#8221;;<\/p>\n<p>$DB_NAME = &#8220;mysql&#8221;;<\/p>\n<p>$DB_USER = &#8220;mysql&#8221;;<\/p>\n<p>$DB_PASS = &#8220;password&#8221;;<\/p>\n<p>function conn_db(){<\/p>\n<p>global $DB_HOST;<\/p>\n<p>global $DB_USER;<\/p>\n<p>global $DB_PASS;<\/p>\n<p>global $DB_NAME;<\/p>\n<p>if(!($conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASS))) {<\/p>\n<p>echo &#8220;Failed to connect DB&#8221;;<\/p>\n<p>echo mysql_error($conn);<\/p>\n<p>die;<\/p>\n<p>}<\/p>\n<p>if(!(mysql_select_db($DB_NAME))) {<\/p>\n<p>echo &#8220;Failed to select DB&#8221;;<\/p>\n<p>echo mysql_error($conn);<\/p>\n<p>die;<\/p>\n<p>}<\/p>\n<p>return $conn;<\/p>\n<p>}<\/p>\n<p>function close_db($conn){<\/p>\n<p>mysql_close($conn);<\/p>\n<p>}<\/p>\n<p>$conn = conn_db();<\/p>\n<p>$sql = &#8220;select * from users where date&gt;&#8217;20081001&#8242; order by id&#8221;;<\/p>\n<p>if (!($rs=mysql_query($sql))) {<\/p>\n<p><span style=\"line-height: 26px;\"> echo mysql_error($conn);<\/span><\/p>\n<p>die;<\/p>\n<p>}<\/p>\n<p>while ($row = mysql_fetch_array($rs)) {<\/p>\n<p>echo &#8220;$row[0] $row[1]\\n&#8221;;<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Connect and Close connection to DB $DB_HOST = &#8220;localhost&#8221;; $DB_NAME = &#8220;mysql&#8221;; $DB_USER = &#8220;mysql&#8221;; $DB_PASS = &#8220;password&#8221;; function conn_db(){ global $DB_HOST; global $DB_USER; global $DB_PASS; global $DB_NAME; if(!($conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASS))) { echo &#8220;Failed to connect DB&#8221;; echo &hellip; <a href=\"http:\/\/www.lalife.net\/?p=45\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,24],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-mysql","category-php"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":1,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":1957,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions\/1957"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}