cvs: functable /lib dbconnect.php

From: Date: Sat, 03 Sep 2005 15:34:55 +0000
Subject: cvs: functable /lib dbconnect.php
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-822@lists.php.net to get a copy of this message
hholzgra Sat Sep 3 11:34:55 2005 EDT Modified files: /functable/lib dbconnect.php Log: first simple steps towards database abstraction http://cvs.php.net/diff.php/functable/lib/dbconnect.php?r1=1.2&r2=1.3&ty=u Index: functable/lib/dbconnect.php diff -u functable/lib/dbconnect.php:1.2 functable/lib/dbconnect.php:1.3 --- functable/lib/dbconnect.php:1.2 Thu Oct 23 03:11:44 2003 +++ functable/lib/dbconnect.php Sat Sep 3 11:34:54 2005 @@ -1,7 +1,36 @@ <?php -$db = mysql_connect($dbhost, $dbuser, $dbpass); -if(! $db) { echo mysql_error(); exit(3); } -if(! mysql_select_db($dbname)) { echo mysql_error(); exit(3);} +function db_connect() { + global $dbhost, $dbuser, $dbpass, $dbname; + $db = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); + mysql_select_db($dbname) or die(mysql_error()); + return $db; +} +function db_query($query) +{ + $result = mysql_query($query) or die(mysql_error()); + return $result; +} + +function db_fetch($result) +{ + $row = mysql_fetch_assoc($result); + if (!$row) { + if (!is_resource($result)) die(mysql_error()); + } + return $row; +} + +function db_free($result) +{ + return mysql_free_result($result) or die(mysql_error()); +} + +function db_close() +{ + mysql_close(); +} + +db_connect(); ?> \ No newline at end of file

« previous php.doc.web (#822) next »