cvs: functable /lib dbconnect.php

[email protected] ("Hartmut Holzgraefe")
Newsgroups php.doc.web
Message-ID <cvshholzgra1125761695@cvsserver>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.