mysql.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 class DB_mysql
00029 {
00035 var $connection;
00036
00042 var $error;
00043
00044
00045 function connect( $conf )
00046 {
00047 $host = $conf['host'];
00048 $user = $conf['user'];
00049 $pw = $conf['password'];
00050 $db = $conf['database'];
00051
00052 if ( isset($conf['port']) )
00053 $host .= ':'.$conf['port'];
00054
00055 if ( $conf['persistent'] )
00056 $connect_function = 'mysql_pconnect';
00057 else
00058 $connect_function = 'mysql_connect';
00059
00060 if ( $pw != '' )
00061 $this->connection = @$connect_function( $host,$user,$pw );
00062 elseif ( $user != '' )
00063 $this->connection = @$connect_function( $host,$user );
00064 elseif ( $host != '' )
00065 $this->connection = @$connect_function( $host );
00066 else
00067 $this->connection = @$connect_function();
00068
00069 if ( !is_resource($this->connection) )
00070 {
00071 $this->error = "Could not connect to database on host $host.";
00072 return false;
00073 }
00074
00075 if ( $db != '' )
00076 {
00077 if ( !@mysql_select_db( $db,$this->connection ) )
00078 {
00079 $this->error = "Could not select database '$db' on host $host.";
00080 return false;
00081 }
00082 }
00083
00084 return true;
00085 }
00086
00087
00088
00089 function disconnect()
00090 {
00091 $ret = mysql_close( $this->connection );
00092 $this->connection = null;
00093 return $ret;
00094 }
00095
00096
00097
00098 function query($query)
00099 {
00100 $result = mysql_query($query, $this->connection);
00101
00102 if ( ! $result )
00103 {
00104 $this->error = 'Database error: '.mysql_error();
00105 return FALSE;
00106 }
00107
00108 return $result;
00109 }
00110
00111
00112 function fetchRow( $result, $rownum )
00113 {
00114 return mysql_fetch_array( $result,MYSQL_ASSOC );
00115 }
00116
00117
00118 function freeResult($result)
00119 {
00120 if ( is_resource($result) )
00121 return mysql_free_result($result);
00122 return true;
00123 }
00124
00125
00126 function numCols($result)
00127 {
00128 return mysql_num_fields( $result );
00129 }
00130
00131
00132
00133 function numRows( $result )
00134 {
00135 return mysql_num_rows($result);
00136 }
00137 }
00138
00139 ?>