3 include_once(dirname(__FILE__) . "/sqlconf.php");
4 require_once(dirname(__FILE__) . "/adodb/adodb.inc.php");
6 define('ADODB_FETCH_ASSOC',2);
7 $database = NewADOConnection("mysql");
8 $database->PConnect($host, $login, $pass, $dbase);
9 $GLOBALS['adodb']['db'] = $database;
10 $GLOBALS['dbh'] = $database->_connectionID;
12 //fmg: This makes the login screen informative when no connection can be made...
13 if (!$GLOBALS['dbh']) {
14 //try to be more helpful
15 if ($host == "localhost") {
16 echo "Check that mysqld is running.<p>";
18 echo "Check that you can ping the server '$host'.<p>";
20 HelpfulDie("Could not connect to server!",mysql_error());
24 function sqlConnect($login,$pass,$dbase,$host,$port = '3306')
26 return $GLOBALS['dbh'] = $database->_connectionID;
29 function sqlStatement($statement)
31 //----------run a mysql query, return the handle
32 $query = mysql_query($statement, $GLOBALS['dbh']) or
33 HelpfulDie("query failed: $statement (".mysql_error().")");
37 function idSqlStatement($statement)
39 //----------run a mysql query, return the handle
40 $query = mysql_query($statement, $GLOBALS['dbh']) or
41 HelpfulDie("query failed: $statement (".mysql_error().")");
42 return mysql_insert_id();
48 //----------Close our mysql connection
49 $closed = mysql_close($GLOBALS['dbh']) or
50 HelpfulDie("could not disconnect from mysql server link (".mysql_error().")");
54 function sqlInsert($statement)
56 //----------run a mysql insert, return the last id generated
57 mysql_query($statement, $GLOBALS['dbh']) or
58 HelpfulDie("insert failed: $statement (".mysql_error().")");
59 return mysql_insert_id($GLOBALS['dbh']);
62 function sqlInsertClean($statement)
64 //----------run a mysql insert, return the last id generated
65 mysql_query($statement, $GLOBALS['dbh']) or
66 HelpfulDie("insert failed: $statement (".mysql_error().")");
67 return mysql_insert_id($GLOBALS['dbh']);
70 function sqlFetchArray($resource)
72 if ($resource == FALSE)
74 return mysql_fetch_array($resource, MYSQL_ASSOC);
77 function sqlQuery ($statement)
79 //echo "[$statement]<br>";
80 //echo "link is: " . $GLOBALS['dbh'];
81 $query = mysql_query($statement, $GLOBALS['dbh']) or
82 HelpfulDie("query failed: $statement (".mysql_error().")");
83 $rez = @mysql_fetch_array($query, MYSQL_ASSOC);
88 function sqlListFields($table) {
90 $sql = "SHOW COLUMNS FROM ". mysql_real_escape_string($table);
92 $field_list = array();
93 while($row = mysql_fetch_array($res)) {
94 $field_list[] = $row['Field'];
98 function sqlLastID() {
99 return mysql_insert_id($GLOBALS['dbh']);
102 function sqlQ ($statement)
104 //echo "[$statement]<br>";
105 //echo "link is: " . $GLOBALS['dbh'];
106 $query = mysql_query($statement, $GLOBALS['dbh']) or
107 HelpfulDie("query failed: $statement (".mysql_error().")");
112 return $GLOBALS['adodb']['db'];
114 function generate_id () {
115 $database = $GLOBALS['adodb']['db'];
116 return $database->GenID("sequences");
119 //fmg: Much more helpful that way...
120 function HelpfulDie ($statement,$sqlerr)
122 echo "<p><p><font color='red'>ERROR:</font> $statement<p>";
124 echo "Error: <font color='red'>$sqlerr</font><p>";