~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/database_interface.lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
/**
4
4
 * Common Option Constants For DBI Functions
5
5
 *
6
 
 * @version $Id: database_interface.lib.php 13108 2009-11-08 11:33:28Z lem9 $
 
6
 * @version $Id: database_interface.lib.php 13180 2009-12-27 13:59:08Z helmo $
7
7
 * @package phpMyAdmin
8
8
 */
9
9
if (! defined('PHPMYADMIN')) {
17
17
define('PMA_DBI_QUERY_STORE',       1);  // Force STORE_RESULT method, ignored by classic MySQL.
18
18
define('PMA_DBI_QUERY_UNBUFFERED',  2);  // Do not read whole query
19
19
// PMA_DBI_get_variable()
20
 
define('PMA_DBI_GETVAR_SESSION', 1);
21
 
define('PMA_DBI_GETVAR_GLOBAL', 2);
 
20
define('PMA_DBI_GETVAR_SESSION',    1);
 
21
define('PMA_DBI_GETVAR_GLOBAL',     2);
22
22
 
23
23
/**
24
24
 * Checks one of the mysql extensions
33
33
    return true;
34
34
}
35
35
 
36
 
 
37
36
/**
38
37
 * check for requested extension
39
38
 */
826
825
}
827
826
 
828
827
/**
 
828
 * array PMA_DBI_get_column_values (string $database, string $table, string $column , mysql db link $link = null)
 
829
 *
 
830
 * @param   string  $database   name of database
 
831
 * @param   string  $table      name of table to retrieve columns from
 
832
 * @param   string  $column     name of the column to retrieve data from 
 
833
 * @param   mixed   $link       mysql link resource
 
834
 * @return  array   $field_values
 
835
 */
 
836
 
 
837
function PMA_DBI_get_column_values($database, $table, $column, $link = null)
 
838
 
839
    $query = 'SELECT ';
 
840
    for($i=0; $i< sizeof($column); $i++)
 
841
    {
 
842
        $query.= PMA_backquote($column[$i]);
 
843
        if($i < (sizeof($column)-1))
 
844
        {
 
845
            $query.= ', ';   
 
846
        }
 
847
    }
 
848
    $query.= ' FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table);
 
849
    $field_values = PMA_DBI_fetch_result($query, null, null, $link);
 
850
    
 
851
    if (! is_array($field_values) || count($field_values) < 1) {
 
852
        return false;
 
853
    }
 
854
    return $field_values;
 
855
}
 
856
/**
 
857
 * array PMA_DBI_get_table_data (string $database, string $table, mysql db link $link = null)
 
858
 *
 
859
 * @param   string  $database   name of database
 
860
 * @param   string  $table      name of table to retrieve columns from
 
861
 * @param   mixed   $link       mysql link resource
 
862
 * @return  array   $result
 
863
 */
 
864
 
 
865
 function PMA_DBI_get_table_data($database, $table, $link = null)
 
866
 { 
 
867
                           
 
868
    $result = PMA_DBI_fetch_result(
 
869
        'SELECT * FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
 
870
        null,null, $link);
 
871
                           
 
872
    if (! is_array($result) || count($result) < 1) {
 
873
        return false;
 
874
    }                                                                                         
 
875
    return $result;
 
876
 }
 
877
 
 
878
/**
 
879
* array  PMA_DBI_get_table_indexes($database, $table, $link = null)
 
880
 
881
* @param    string  $database   name of database
 
882
* @param    string  $table      name of the table whose indexes are to be retreived
 
883
* @param    mixed   $link       mysql link resource
 
884
* @return   array   $indexes
 
885
*/
 
886
 
 
887
function PMA_DBI_get_table_indexes($database, $table, $link = null)
 
888
{
 
889
 
 
890
    $indexes = PMA_DBI_fetch_result(
 
891
              'SHOW INDEXES FROM ' .PMA_backquote($database) . '.' . PMA_backquote($table),
 
892
               null, null, $link);  
 
893
    
 
894
    if (! is_array($indexes) || count($indexes) < 1) {
 
895
        return false;
 
896
    }
 
897
    return $indexes;
 
898
}
 
899
 
 
900
 /**
829
901
 * returns value of given mysql server variable
830
902
 *
831
903
 * @param   string  $var    mysql server variable name
833
905
 * @param   mixed   $link   mysql link resource|object
834
906
 * @return  mixed   value for mysql server variable
835
907
 */
 
908
 
 
909
 
836
910
function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION, $link = null)
837
911
{
838
912
    if ($link === null) {
858
932
}
859
933
 
860
934
/**
 
935
 *  Function called just after a connection to the MySQL database server has been established
 
936
 *  It sets the connection collation, and determins the version of MySQL which is running.
 
937
 *
861
938
 * @uses    ./libraries/charset_conversion.lib.php
862
939
 * @uses    PMA_DBI_QUERY_STORE
863
940
 * @uses    PMA_MYSQL_INT_VERSION to set it
1315
1392
 * @uses    PMA_DBI_fetch_result()
1316
1393
 * @param   string              $db     db name
1317
1394
 * @param   string              $table  table name
1318
 
 * @param   string              $delimiter  the delimiter to use (may be empty)
 
1395
 * @param   string              $delimiter  the delimiter to use (may be empty) 
1319
1396
 *
1320
1397
 * @return  array               information about triggers (may be empty)
1321
1398
 */
1357
1434
    }
1358
1435
    return($result);
1359
1436
}
 
1437
 
 
1438
/**
 
1439
 * Returns TRUE if $db.$view_name is a view, FALSE if not
 
1440
 *
 
1441
 * @uses   PMA_DBI_fetch_result()
 
1442
 * @param  string $db         database name
 
1443
 * @param  string $view_name  view/table name
 
1444
 *
 
1445
 * @return bool               TRUE if $db.$view_name is a view, FALSE if not
 
1446
 */
 
1447
function PMA_isView($db, $view_name)
 
1448
{
 
1449
    $result = PMA_DBI_fetch_result("SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$db."' and TABLE_NAME = '".$view_name."';");
 
1450
    
 
1451
    if ($result) {
 
1452
        return TRUE;
 
1453
    } else {
 
1454
        return FALSE;
 
1455
    }
 
1456
}
1360
1457
?>