Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查mysql表是否可通过php访问_Php_Mysql_Database_Mysql Error 1064 - Fatal编程技术网

如何检查mysql表是否可通过php访问

如何检查mysql表是否可通过php访问,php,mysql,database,mysql-error-1064,Php,Mysql,Database,Mysql Error 1064,我有一个自托管的web应用程序,我正在尝试访问信息\u模式表,了解如何在某些服务器中禁用它。如何检查它是否可访问?运行显示数据库,查看列表中是否有信息\u架构 但这不重要,对吗?如果您是自托管,您可以根据需要对其进行配置。运行显示数据库,查看列表中是否有信息\u架构 但这不重要,对吗?如果您是自托管,您可以根据需要对其进行配置。将数据库设置为信息模式,并从所选数据库运行查询“显示表”。如果您具有读访问权限,那么您将从该数据库获取所有表。检查所有查询的结果 将数据库设置为信息模式,并从所选数据库运

我有一个自托管的web应用程序,我正在尝试访问
信息\u模式
表,了解如何在某些服务器中禁用它。如何检查它是否可访问?

运行
显示数据库
,查看列表中是否有
信息\u架构


但这不重要,对吗?如果您是自托管,您可以根据需要对其进行配置。

运行
显示数据库
,查看列表中是否有
信息\u架构


但这不重要,对吗?如果您是自托管,您可以根据需要对其进行配置。

将数据库设置为信息模式,并从所选数据库运行查询“显示表”。如果您具有读访问权限,那么您将从该数据库获取所有表。检查所有查询的结果

将数据库设置为信息模式,并从所选数据库运行查询“显示表”。如果您具有读访问权限,那么您将从该数据库获取所有表。检查所有查询的结果

解决此问题的示例解决方案:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>MySQL Connection Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    #wrapper {
        width: 600px;
        margin: 20px auto 0;
        font: 1.2em Verdana, Arial, sans-serif;
    }
    input {
        font-size: 1em;
    }
    #submit {
        padding: 4px 8px;
    }
    </style>
    </head>

    <body>

    <div id="wrapper">

    <?php
        $action = htmlspecialchars($_GET['action'], ENT_QUOTES);
    ?>

    <?php if (!$action) { ?>

        <h1>MySQL connection test</h1>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=test" id="mail" method="post">

        <table cellpadding="2">
            <tr>
                <td>Hostname</td>
                <td><input type="text" name="hostname" id="hostname" value="" size="30" tabindex="1" /></td>
                <td>(usually "localhost")</td>
            </tr>
            <tr>
                <td>Username</td>
                <td><input type="text" name="username" id="username" value="" size="30" tabindex="2" /></td>
                <td></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="text" name="password" id="password" value="" size="30" tabindex="3" /></td>
                <td></td>
            </tr>
            <tr>
                <td>Database</td>
                <td><input type="text" name="database" id="database" value="" size="30" tabindex="4" /></td>
                <td>(optional)</td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" id="submit" value="Test Connection" tabindex="5" /></td>
                <td></td>
            </tr>
        </table>

    </form>

    <?php } ?>

    <?php if ($action == "test") {

    // The variables have not been adequately sanitized to protect against SQL Injection attacks: http://us3.php.net/mysql_real_escape_string

        $hostname = trim($_POST['hostname']);
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        $database = trim($_POST['database']);

        $link = mysql_connect("$hostname", "$username", "$password");
            if (!$link) {
                echo "<p>Could not connect to the server '" . $hostname . "'</p>\n";
                echo mysql_error();
            }else{
                echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n";
    //          printf("MySQL client info: %s\n", mysql_get_client_info());
    //          printf("MySQL host info: %s\n", mysql_get_host_info());
    //          printf("MySQL server version: %s\n", mysql_get_server_info());
    //          printf("MySQL protocol version: %s\n", mysql_get_proto_info());
            }
        if ($link && !$database) {
            echo "<p>No database name was given. Available databases:</p>\n";
            $db_list = mysql_list_dbs($link);
            echo "<pre>\n";
            while ($row = mysql_fetch_array($db_list)) {
                echo $row['Database'] . "\n";
            }
            echo "</pre>\n";
        }
        if ($database) {
        $dbcheck = mysql_select_db("$database");
            if (!$dbcheck) {
                echo mysql_error();
            }else{
                echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
                // Check tables
                $sql = "SHOW TABLES FROM `$database`";
                $result = mysql_query($sql);
                if (mysql_num_rows($result) > 0) {
                    echo "<p>Available tables:</p>\n";
                    echo "<pre>\n";
                    while ($row = mysql_fetch_row($result)) {
                        echo "{$row[0]}\n";
                    }
                    echo "</pre>\n";
                } else {
                    echo "<p>The database '" . $database . "' contains no tables.</p>\n";
                    echo mysql_error();
                }
            }
        }
    }
    ?>

    </div><!-- end #wrapper -->
    </body>
    </html>

MySQL连接测试
#包装纸{
宽度:600px;
利润率:20px自动0;
字体:1.2em Verdana,Arial,无衬线;
}
输入{
字号:1em;
}
#提交{
填充:4px8px;
}
MySQL连接测试

解决此问题的示例解决方案:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>MySQL Connection Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    #wrapper {
        width: 600px;
        margin: 20px auto 0;
        font: 1.2em Verdana, Arial, sans-serif;
    }
    input {
        font-size: 1em;
    }
    #submit {
        padding: 4px 8px;
    }
    </style>
    </head>

    <body>

    <div id="wrapper">

    <?php
        $action = htmlspecialchars($_GET['action'], ENT_QUOTES);
    ?>

    <?php if (!$action) { ?>

        <h1>MySQL connection test</h1>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=test" id="mail" method="post">

        <table cellpadding="2">
            <tr>
                <td>Hostname</td>
                <td><input type="text" name="hostname" id="hostname" value="" size="30" tabindex="1" /></td>
                <td>(usually "localhost")</td>
            </tr>
            <tr>
                <td>Username</td>
                <td><input type="text" name="username" id="username" value="" size="30" tabindex="2" /></td>
                <td></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="text" name="password" id="password" value="" size="30" tabindex="3" /></td>
                <td></td>
            </tr>
            <tr>
                <td>Database</td>
                <td><input type="text" name="database" id="database" value="" size="30" tabindex="4" /></td>
                <td>(optional)</td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" id="submit" value="Test Connection" tabindex="5" /></td>
                <td></td>
            </tr>
        </table>

    </form>

    <?php } ?>

    <?php if ($action == "test") {

    // The variables have not been adequately sanitized to protect against SQL Injection attacks: http://us3.php.net/mysql_real_escape_string

        $hostname = trim($_POST['hostname']);
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        $database = trim($_POST['database']);

        $link = mysql_connect("$hostname", "$username", "$password");
            if (!$link) {
                echo "<p>Could not connect to the server '" . $hostname . "'</p>\n";
                echo mysql_error();
            }else{
                echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n";
    //          printf("MySQL client info: %s\n", mysql_get_client_info());
    //          printf("MySQL host info: %s\n", mysql_get_host_info());
    //          printf("MySQL server version: %s\n", mysql_get_server_info());
    //          printf("MySQL protocol version: %s\n", mysql_get_proto_info());
            }
        if ($link && !$database) {
            echo "<p>No database name was given. Available databases:</p>\n";
            $db_list = mysql_list_dbs($link);
            echo "<pre>\n";
            while ($row = mysql_fetch_array($db_list)) {
                echo $row['Database'] . "\n";
            }
            echo "</pre>\n";
        }
        if ($database) {
        $dbcheck = mysql_select_db("$database");
            if (!$dbcheck) {
                echo mysql_error();
            }else{
                echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
                // Check tables
                $sql = "SHOW TABLES FROM `$database`";
                $result = mysql_query($sql);
                if (mysql_num_rows($result) > 0) {
                    echo "<p>Available tables:</p>\n";
                    echo "<pre>\n";
                    while ($row = mysql_fetch_row($result)) {
                        echo "{$row[0]}\n";
                    }
                    echo "</pre>\n";
                } else {
                    echo "<p>The database '" . $database . "' contains no tables.</p>\n";
                    echo mysql_error();
                }
            }
        }
    }
    ?>

    </div><!-- end #wrapper -->
    </body>
    </html>

MySQL连接测试
#包装纸{
宽度:600px;
利润率:20px自动0;
字体:1.2em Verdana,Arial,无衬线;
}
输入{
字号:1em;
}
#提交{
填充:4px8px;
}
MySQL连接测试

谢谢你,伙计,我在下面为其他人发布答案。如果对你有用,一定要把它标记正确。谢谢你:)谢谢你,伙计,我在下面为其他人发布了答案。如果对你有用,一定要把它标记正确。谢谢:)Dude
信息\u模式
与任何数据库都不相关,因此它不会显示在
显示表
查询中,是的,我需要获得有多少用户可以访问
信息\u模式
如何配置它?Dude
信息\u模式
与任何数据库都不相关,因此它不会显示在
显示中表
query and yes我需要获取有多少用户可以访问
information\u schema
如何配置它?我很高兴它对您有所帮助。谢谢伙计,编码快乐!我很高兴它帮助了你。谢谢你,伙计,编码快乐!