{"id":151,"date":"2013-03-12T08:25:04","date_gmt":"2013-03-12T15:25:04","guid":{"rendered":"http:\/\/www.planetcy.com\/?p=151"},"modified":"2015-02-05T12:04:13","modified_gmt":"2015-02-05T19:04:13","slug":"db-abstraction","status":"publish","type":"post","link":"http:\/\/www.planetcy.com\/?p=151","title":{"rendered":"DB abstraction"},"content":{"rendered":"<p>Config File:<br \/>\n<code><br \/>\n$dbhost = \"MYSQLHOST\"; \/\/hostname of DB server<br \/>\n$dbName = \"MYDB\"; \/\/Name of DB<br \/>\n$dbuser = \"db-username\"; \/\/DB User<br \/>\n$dbpass = \"db-password\"; \/\/DB Pass<br \/>\n\/\/ setting up the web root and server root for<br \/>\n$thisFile = str_replace('\\\\', '\/', __FILE__);<br \/>\n$docRoot = $_SERVER['DOCUMENT_ROOT'];<br \/>\n$webRoot = str_replace(array($docRoot, 'inc\/config.php'), '', $thisFile);<br \/>\n$srvRoot = str_replace('inc\/config.php', '', $thisFile);<br \/>\ndefine('WEB_ROOT', $webRoot);<br \/>\ndefine('SRV_ROOT', $srvRoot);<br \/>\n<\/code><br \/>\n<code><br \/>\nrequire_once 'config.php';<br \/>\n$dbConn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('MySQL connect failed. ' . mysql_error());<br \/>\nmysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());<br \/>\nfunction dbQuery($sql)<br \/>\n{<br \/>\n\t$result = mysql_query($sql) or die(mysql_error());<br \/>\n\treturn $result;<br \/>\n}<\/p>\n<p>function dbAffectedRows()<br \/>\n{<br \/>\n\tglobal $dbConn;<\/p>\n<p>\treturn mysql_affected_rows($dbConn);<br \/>\n}<\/p>\n<p>function dbFetchArray($result, $resultType = MYSQL_NUM) {<br \/>\n\treturn mysql_fetch_array($result, $resultType);<br \/>\n}<\/p>\n<p>function dbFetchAssoc($result)<br \/>\n{<br \/>\n\treturn mysql_fetch_assoc($result);<br \/>\n}<\/p>\n<p>function dbFetchRow($result)<br \/>\n{<br \/>\n\treturn mysql_fetch_row($result);<br \/>\n}<\/p>\n<p>function dbFreeResult($result)<br \/>\n{<br \/>\n\treturn mysql_free_result($result);<br \/>\n}<br \/>\nfunction dbNumRows($result)<br \/>\n{<br \/>\n\treturn mysql_num_rows($result);<br \/>\n}<br \/>\nfunction dbSelect($dbName)<br \/>\n{<br \/>\n\treturn mysql_select_db($dbName);<br \/>\n}<\/p>\n<p>function dbInsertId()<br \/>\n{<br \/>\n\treturn mysql_insert_id();<br \/>\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Config File: $dbhost = &#8220;MYSQLHOST&#8221;; \/\/hostname of DB server $dbName = &#8220;MYDB&#8221;; \/\/Name of DB $dbuser = &#8220;db-username&#8221;; \/\/DB User $dbpass = &#8220;db-password&#8221;; \/\/DB Pass \/\/ setting up the web root and server root for $thisFile = str_replace(&#8216;\\\\&#8217;, &#8216;\/&#8217;, __FILE__); $docRoot = $_SERVER[&#8216;DOCUMENT_ROOT&#8217;]; $webRoot = str_replace(array($docRoot, &#8216;inc\/config.php&#8217;), &#8221;, $thisFile); $srvRoot = str_replace(&#8216;inc\/config.php&#8217;, &#8221;, $thisFile); define(&#8216;WEB_ROOT&#8217;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["bg-stuff"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151"}],"version-history":[{"count":25,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":176,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions\/176"}],"wp:attachment":[{"href":"http:\/\/www.planetcy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.planetcy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}