首页 > 代码库 > 辅导日

辅导日

今天看了mysql,看完后又懵逼了...完全不会,而且新东西好多,晚上写代码都感觉稍微明白了一点...

技术分享

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<?php
    $link = mysql_connect(‘localhost‘, ‘root‘, ‘admin‘);
    mysql_query(‘set names utf8‘);
    $databases = mysql_query(‘show databases‘);
    if(!$databases){
        echo "执行失败,请参考:".mysql_error();
    }
    else{
        echo "执行成功!数据如下:";
        while($res = mysql_fetch_array($databases)){
            echo "<br>".$res[0];
            echo " <a href=http://www.mamicode.com/‘mysql_tables.php?db={$res[0]}‘>查看表</a>";
        }
    }
?>
    
</body>
</html>
<?php
    $db = $_GET[‘db‘];
    $link = mysql_connect(‘localhost‘,‘root‘,‘admin‘);
    mysql_query(‘set names utf8‘);
    mysql_query("use $db");
    $table = mysql_query(‘show tables‘);
    if(!$table){
        echo "执行失败,请参考:".mysql_error();
    }
    else{
        echo "执行成功!数据如下:";
        while($res=mysql_fetch_array($table)){
            echo ‘<br>‘.$res[0];
            echo " <a href = http://www.mamicode.com/mysql_table_struct.php?db=$db&table={$res[0]}>查看结构</a>";
            echo " <a href = http://www.mamicode.com/mysql_table_data.php?db=$db&table={$res[0]}>查看数据</a>";
        }
    }
?>
<?php
    $db = $_GET[‘db‘];
    $table = $_GET["table"];
    $link = mysql_connect(‘localhost‘,‘root‘,‘admin‘);
    mysql_query(‘set names utf8‘);
    mysql_query("use $db");
    $struct = mysql_query("desc $table");
    if(!$struct){
        echo "执行失败,请参考:".mysql_error();
    }
    else{
        echo "执行成功!数据如下:";
        echo "<table border=‘1‘>";
        $field_count = mysql_num_fields($struct);
        echo "<tr>";
        for($i=0; $i<$field_count; ++$i){
            $file_name = mysql_field_name($struct,$i);
            echo "<td>".$file_name."</td>";
        }
        echo "</tr>";
        while($res = mysql_fetch_array($struct)){
            echo "<tr>";
            for($i=0; $i<$field_count; ++$i){
                echo "<td>".$res[$i]."</td>";
            }
            echo "</tr>";
        }
        echo "</table>";


    }
    
?>
<?php
    $db = $_GET[‘db‘];
    $table = $_GET["table"];    
    $link = mysql_connect("localhost","root","admin");
    mysql_query("set names utf8");
    mysql_query("use $db");
    $data = mysql_query("select * from $table");
    if(!$data){
        echo "执行失败,请参考:".mysql_error();
    }
    else{
        echo "执行成功!数据如下:";
        echo "<table border=‘1‘>";
        $field_count = mysql_num_fields($data);
        echo "<tr>";
        for($i=0; $i<$field_count; ++$i){
            $field_name = mysql_field_name($data,$i);
            echo "<td>".$field_name."</td>";
        }
        echo "</tr>";        
        while($res = mysql_fetch_array($data)){
            echo "<tr>";
            for($i=0; $i<$field_count; ++$i){
                echo "<td>".$res[$i]."</td>";
            }
            echo "</tr>";    
        }        
        echo "</table>";
    }
?>

 

辅导日