Beispiel #1
0
 /**
  *  Connect to a MySQL database server.
  *  @param string $dbtype db selector (db_write,db_read)
  *  @return resource|boolean
  */
 function connect($dbtype = 'db_write')
 {
     if (is_resource($this->{$dbtype}) && @mysql_db_name($this->{$dbtype})) {
         return $this->{$dbtype};
     }
     $details = $this->db_details[$dbtype];
     $db = @mysql_pconnect($details['host'], $details['user'], $details['pass']);
     if (is_resource($db) && !@mysql_db_name($db)) {
         @mysql_select_db($details['name'], $db);
         $this->{$dbtype} = $db;
         return $this->{$dbtype};
     }
     /**
      * If we can't connect at all then we have to show a fallback page w/
      * the correct error code.
      */
     header('HTTP/1.0 500 Internal Server Error');
     require_once FILEPATH . '/gonefishing.php';
     exit;
 }
Beispiel #2
0
 function dbnames($options)
 {
     $options = $options['base'];
     $link = @mysql_connect($options['database.host'], $options['database.username'], $options['database.password']);
     if (!$link) {
         return array();
     } else {
         if (function_exists('mysql_list_dbs')) {
             $db_list = mysql_list_dbs($link);
         } else {
             $db_list = mysql_query('SHOW databases');
         }
         //todo: 加强兼容性
         $i = 0;
         $cnt = mysql_num_rows($db_list);
         $rows = array();
         while ($i < $cnt) {
             $dbname = trim(mysql_db_name($db_list, $i++));
             $rows[$dbname] = $dbname;
         }
         return $rows;
     }
 }
Beispiel #3
0
 /**
  * Test mysql_db_name
  *
  * @return boolean
  */
 public function MySQL_Db_Name_Test()
 {
     // Connect
     $this->_getConnection();
     $dbs1 = mysql_list_dbs();
     $list1 = array();
     $i = 0;
     $cnt = mysql_num_rows($dbs1);
     while ($i < $cnt) {
         $list1[] = mysql_db_name($dbs1, $i);
         $i++;
     }
     return in_array('unit_sql_v_1', $list1) && in_array('unit_sql_v_2', $list1);
 }
		</tr>
		</table><br>
		<input type="submit" name="submit" value="Submit">
		</form>' . PHP_EOL;
} else {
    if (!isset($db)) {
        $dbs = @mysql_list_dbs($dbl);
        $num_dbs = @mysql_num_rows($dbs);
        echo '<h1>Please select a database</h1>
		<form action="' . htmlspecialchars($self) . '" method="POST">
		<input type="hidden" name="hn" value="' . htmlspecialchars($hn) . '">
		<input type="hidden" name="un" value="' . htmlspecialchars($un) . '">
		<input type="hidden" name="pw" value="' . htmlspecialchars($pw) . '">
		<table border="1" cellpadding="1" cellspacing="1" summary="Database selection">' . PHP_EOL;
        for ($i = 0; $i < $num_dbs; $i++) {
            $db = @mysql_db_name($dbs, $i);
            $checked = !strcasecmp($un, $db) ? ' checked' : '';
            $db = htmlspecialchars($db);
            echo '<tr><td><input' . $checked . ' type="radio" name="db" value="' . $db . '"></td><td>' . $db . '</td></tr>' . PHP_EOL;
        }
        echo '</table><br>
		<input type="submit" name="submit" value="Submit">
		<input type="submit" name="cancel" value="Cancel">
		</form>' . PHP_EOL;
    } else {
        if (!isset($tb)) {
            echo '<h1>Please select a table from database: ' . htmlspecialchars($db) . '</h1>
		<form action="' . htmlspecialchars($self) . '" method="POST">
		<input type="hidden" name="hn" value="' . htmlspecialchars($hn) . '">
		<input type="hidden" name="un" value="' . htmlspecialchars($un) . '">
		<input type="hidden" name="pw" value="' . htmlspecialchars($pw) . '">
Beispiel #5
0
    function availableDatabases()
    {
        $databaseArray = mysql_list_dbs( $this->DBConnection );

        if ( $this->errorNumber() != 0 )
        {
            return null;
        }

        $databases = array();
        $i = 0;
        $numRows = mysql_num_rows( $databaseArray );
        if ( count( $numRows ) == 0 )
        {
            return false;
        }

        while ( $i < $numRows )
        {
            // we don't allow "mysql" or "information_schema" database to be shown anywhere
            $curDB = mysql_db_name( $databaseArray, $i );
            if ( strcasecmp( $curDB, 'mysql' ) != 0 && strcasecmp( $curDB, 'information_schema' ) != 0 )
            {
                $databases[] = $curDB;
            }
            ++$i;
        }
        return $databases;
    }
Beispiel #6
0
 public function databases()
 {
     $rsPtr = mysql_list_dbs($this->conn);
     $i = 0;
     $cnt = mysql_num_rows($rsPtr);
     while ($i < $cnt) {
         $rs[] = mysql_db_name($rsPtr, $i);
         $i++;
     }
     return $rs;
 }
Beispiel #7
0
                            ?>
    

			<table>  
                <thead>  
                    <tr>                      
						<th>db_name</th>
                    </tr>  
                </thead>                
                <tbody>  

<?php 
                            $dbs = mysql_list_dbs();
                            ## Menampilkan semua nama database yang ada di server
                            for ($i = 0; $i < mysql_num_rows($dbs); $i++) {
                                $dbname = mysql_db_name($dbs, $i);
                                echo '<tr><td>' . $dbname . '</td></tr>';
                            }
                            ?>

				</tbody> 
			</table>

<?php 
                        }
                    }
                }
            }
        }
    }
}
Beispiel #8
0
 function mysql_dbname(...$args)
 {
     return mysql_db_name(...$args);
 }
Beispiel #9
0
<?php

require_once 'connect.inc';
$conn = mysql_connect($host, $user, $passwd);
$dbs = mysql_list_dbs();
var_dump((bool) mysql_db_name($dbs, 0));
Beispiel #10
0
  <?php 
$menu = array('database' => 'database', 'server' => 'server', 'user' => 'user', 'permissions' => 'permissions');
$mymenu = new Menu();
$mymenu->themenu($menu);
if ($_GET['menu'] == 'database') {
    //echo mysql_get_server_info($connection);
    echo '<div class="database">';
    $num_rows = mysql_num_rows(mysql_query("SHOW TABLES"));
    $query = mysql_query("SHOW TABLES;");
    echo "<h2>" . mysql_db_name($query, 2) . "</h2>";
    echo "<b>Database Tables</b><br />";
    //mysql_list_tables(mysql_db_name($query,1));
    while (list($table) = mysql_fetch_array($query)) {
        echo '<h3>' . str_replace("_", " ", ucwords($table)) . "</h3>";
        $myquery = mysql_query("SELECT * FROM {$table}");
        $result = mysql_fetch_assoc($myquery);
        if ($result != null) {
            foreach ($result as $key => $value) {
                echo "<b>{$key}:</b>{$value}<br />&nbsp;&nbsp;&nbsp;";
            }
        } else {
            echo "No data found.";
        }
    }
    echo '</div>';
    //include "database.php";
} elseif ($_GET['menu'] == 'server') {
    include "server.php";
} elseif ($_GET['menu'] == 'user') {
    include "user.php";
} elseif ($_GET['menu'] == 'permissions') {
 function mysql_db_name($row)
 {
     return mysql_db_name($this->res, $row);
 }
Beispiel #12
0
    printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
require 'table.inc';
if (!($res = @mysql_list_dbs($link))) {
    printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
if (!($num = mysql_num_rows($res))) {
    printf("[004] Empty database list? [%d] %s\n", mysql_errno($link), mysql_error($link));
}
if (false !== ($tmp = mysql_db_name($res, -1))) {
    printf("[005] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
}
if (false !== ($tmp = mysql_db_name($res, $num + 1))) {
    printf("[006] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
}
$unicode = (bool) (version_compare(PHP_VERSION, '5.9.9', '>') == 1);
for ($i = 0; $i < $num; $i++) {
    if ('' === ($dbname = mysql_db_name($res, $i))) {
        printf("[%03d] Got empty database name! [%d] %s\n", $i * 2 + 1 + 6, mysql_errno($link), mysql_error($link));
    }
    if ($unicode && !is_unicode($dbname)) {
        printf("[%03d] Expecting unicode string! [%d] %s\n", $i * 2 + 2 + 6, mysql_errno($link), mysql_error($link));
        var_inspect($dbname);
    }
}
mysql_free_result($res);
if (false !== ($tmp = mysql_db_name($res, $num))) {
    printf("[999] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
}
mysql_close($link);
print "done!\n";

<p>Target Database:</p>
<form action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="POST">
<select name="database">

<?php 
if (!($dbs = mysql_list_dbs())) {
    echo mysql_error() . "\n";
    exit;
}
for ($i = 0; $i < mysql_num_rows($dbs); $i++) {
    if (!($dbname = mysql_db_name($dbs, $i))) {
        echo mysql_error() . "\n";
        exit;
    }
    if ($dbname == $_POST['database']) {
        echo "<option selected=\"selected\" value=\"{$dbname}\">{$dbname}</option>\n";
    } else {
        echo "<option value=\"{$dbname}\">{$dbname}</option>\n";
    }
}
?>
</select>

<p>SQL Query:</p>
<textarea onFocus="this.select()" cols="60" rows="5" name="query">
<?php 
Beispiel #14
0
 ***************************************************************************/
// List of tables used
//-- mod : db maintenance addon ------------------------------------------------
//-- delete
/*-MOD
$tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words');
MOD-*/
//-- add
if ($err = mysql_error()) {
    exit($err);
}
$tablesid = @mysql_list_tables($dbname);
$k = 0;
$num_tables = mysql_num_rows($tablesid);
for ($j = 0; $j < $num_tables; $j++) {
    $nom = mysql_db_name($tablesid, $j);
    if (preg_match("/" . $table_prefix . "/i", $nom)) {
        $nom = str_replace($table_prefix, "", $nom);
        $tables[$k] = $nom;
        $k = $k + 1;
    }
}
//-- fin mod : db maintenance addon --------------------------------------------
// List of configuration data required
$config_data = array('dbmtnc_disallow_postcounter', 'dbmtnc_disallow_rebuild', 'dbmtnc_rebuildcfg_maxmemory', 'dbmtnc_rebuildcfg_minposts', 'dbmtnc_rebuildcfg_php3only', 'dbmtnc_rebuildcfg_php3pps', 'dbmtnc_rebuildcfg_php4pps', 'dbmtnc_rebuildcfg_timeoverwrite', 'dbmtnc_rebuildcfg_timelimit', 'dbmtnc_rebuild_end', 'dbmtnc_rebuild_pos');
// Default configuration records - from installation file
$default_config = array('config_id' => '1', 'board_disable' => '0', 'sitename' => 'yourdomain.com', 'site_desc' => 'A _little_ text to describe your forum', 'cookie_name' => 'phpbb2mysql', 'cookie_path' => '/', 'cookie_domain' => '', 'cookie_secure' => '0', 'session_length' => '3600', 'allow_html' => '0', 'allow_html_tags' => 'b,i,u,pre', 'allow_bbcode' => '1', 'allow_smilies' => '1', 'allow_sig' => '1', 'allow_namechange' => '0', 'allow_theme_create' => '0', 'allow_avatar_local' => '0', 'allow_avatar_remote' => '0', 'allow_avatar_upload' => '0', 'enable_confirm' => '0', 'override_user_style' => '0', 'posts_per_page' => '15', 'topics_per_page' => '50', 'hot_threshold' => '25', 'max_poll_options' => '10', 'max_sig_chars' => '255', 'max_inbox_privmsgs' => '50', 'max_sentbox_privmsgs' => '25', 'max_savebox_privmsgs' => '50', 'board_email_sig' => 'Thanks, The Management', 'board_email' => '*****@*****.**', 'smtp_delivery' => '0', 'smtp_host' => '', 'smtp_username' => '', 'smtp_password' => '', 'sendmail_fix' => '0', 'require_activation' => '0', 'flood_interval' => '15', 'board_email_form' => '0', 'avatar_filesize' => '6144', 'avatar_max_width' => '80', 'avatar_max_height' => '80', 'avatar_path' => 'images/avatars', 'avatar_gallery_path' => 'images/avatars/gallery', 'smilies_path' => 'images/smiles', 'default_style' => '1', 'default_dateformat' => 'D M d, Y g:i a', 'board_timezone' => '0', 'prune_enable' => '1', 'privmsg_disable' => '0', 'gzip_compress' => '0', 'coppa_fax' => '', 'coppa_mail' => '', 'record_online_users' => '0', 'record_online_date' => '0', 'server_name' => 'www.myserver.tld', 'server_port' => '80', 'script_path' => '/phpBB2/', 'version' => '.0.0', 'default_lang' => 'english', 'board_startdate' => '0', 'dbmtnc_rebuild_end' => '0', 'dbmtnc_rebuild_pos' => '-1', 'dbmtnc_rebuildcfg_maxmemory' => '500', 'dbmtnc_rebuildcfg_minposts' => '3', 'dbmtnc_rebuildcfg_php3only' => '0', 'dbmtnc_rebuildcfg_php3pps' => '1', 'dbmtnc_rebuildcfg_php4pps' => '8', 'dbmtnc_rebuildcfg_timelimit' => '240', 'dbmtnc_rebuildcfg_timeoverwrite' => '0', 'dbmtnc_disallow_postcounter' => '0', 'dbmtnc_disallow_rebuild' => '0');
// append data added in later versions
if (isset($board_config) && isset($board_config['version'])) {
    $phpbb_version = explode('.', substr($board_config['version'], 1));
} else {
Beispiel #15
0
 function mysql_dbname($result, $row, $field = null)
 {
     return mysql_db_name($result, $row, $field);
 }
Beispiel #16
0
 function dbName($row, $field = NULL)
 {
     /* 取得结果数据 */
     if (empty($field)) {
         return mysql_db_name($this->Result, $row);
     }
     return mysql_db_name($this->Result, $row, $field);
 }
Beispiel #17
0
 /**
  * Test mysql_db_name
  *
  * @return boolean
  */
 public function MySQL_Db_Name_Test()
 {
     // Connect
     list($mysql, $ourDb) = $this->_getConnection();
     $dbs1 = mysql_list_dbs();
     $dbs2 = $this->_object->mysql_list_dbs();
     $list1 = array();
     $list2 = array();
     $i = 0;
     $cnt = mysql_num_rows($dbs1);
     while ($i < $cnt) {
         $list1[] = mysql_db_name($dbs1, $i);
         $i++;
     }
     $i = 0;
     $cnt = $this->_object->mysql_num_rows($dbs2);
     while ($i < $cnt) {
         $list2[] = $this->_object->mysql_db_name($dbs2, $i);
         $i++;
     }
     return $list1 === $list2;
 }
Beispiel #18
0
    }
    echo $row['id'] . ' ' . $row['email'] . "<br />\n";
}
mysql_free_result($result);
//释放结果内存
?>
-------------<br>
<?php 
error_reporting(E_ALL);
$link1 = mysql_connect('pma.host', 'root', '123456');
$db_list = mysql_query('SHOW DATABASES', $link1);
//取得服务器里面的database
$i = 0;
$cnt = mysql_num_rows($db_list);
while ($i < $cnt) {
    echo mysql_db_name($db_list, $i) . "<br />\n";
    //返回结果指针数据库的名字
    $i++;
}
?>
-------------<br>
<?php 
mysql_connect('pma.host', 'root', '123456') or die("Could not connect: " . mysql_error());
mysql_select_db("bookmarks");
$result = mysql_query("SELECT id, email FROM users");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    //从集中行中取得一行作为关联数组
    printf("ID: %s  Name: %s", $row[0], $row[1]);
    echo "<br />\n";
}
mysql_free_result($result);