includes/dbal.php
changeset 1147 7ddd475bc661
parent 1143 e271ae801c62
child 1165 ce8aaa2956d1
equal deleted inserted replaced
1146:4a90e6e46937 1147:7ddd475bc661
   507   {
   507   {
   508     if(!$this->_conn) return false;
   508     if(!$this->_conn) return false;
   509     if(!$r) $r = $this->latest_result;
   509     if(!$r) $r = $this->latest_result;
   510     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
   510     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
   511     return mysql_affected_rows();
   511     return mysql_affected_rows();
       
   512   }
       
   513   
       
   514   /**
       
   515    * Get a list of columns in the given table
       
   516    * @param string Table
       
   517    * @return array
       
   518    */
       
   519   
       
   520   function columns_in($table)
       
   521   {
       
   522     if ( !is_string($table) )
       
   523       return false;
       
   524     $q = $this->sql_query("SHOW COLUMNS IN $table;");
       
   525     if ( !$q )
       
   526       $this->_die();
       
   527     
       
   528     $columns = array();
       
   529     while ( $row = $this->fetchrow_num() )
       
   530     {
       
   531       $columns[] = $row[0];
       
   532     }
       
   533     return $columns;
   512   }
   534   }
   513   
   535   
   514   function sql_type_cast(&$value)
   536   function sql_type_cast(&$value)
   515 	{
   537 	{
   516 		if ( is_float($value) )
   538 		if ( is_float($value) )
  1217     if(!$r) $r = $this->latest_result;
  1239     if(!$r) $r = $this->latest_result;
  1218     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1240     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1219     return pg_affected_rows();
  1241     return pg_affected_rows();
  1220   }
  1242   }
  1221   
  1243   
       
  1244   /**
       
  1245    * Get a list of columns in the given table
       
  1246    * @param string Table
       
  1247    * @return array
       
  1248    */
       
  1249   
       
  1250   function columns_in($table)
       
  1251   {
       
  1252     if ( !is_string($table) )
       
  1253       return false;
       
  1254     $q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
       
  1255     if ( !$q )
       
  1256       $this->_die();
       
  1257     if ( $this->numrows() < 1 )
       
  1258     {
       
  1259       // FIXME: Have another way to do this if the table is empty
       
  1260       return false;
       
  1261     }
       
  1262     
       
  1263     $row = $this->fetchrow();
       
  1264     $this->free_result();
       
  1265     return array_keys($row);
       
  1266   }
       
  1267   
  1222   function sql_type_cast(&$value)
  1268   function sql_type_cast(&$value)
  1223 	{
  1269 	{
  1224 		if ( is_float($value) )
  1270 		if ( is_float($value) )
  1225 		{
  1271 		{
  1226 			return doubleval($value);
  1272 			return doubleval($value);