Home > php教程 > php手册 > php mysql 连接数据库选择显示所有表

php mysql 连接数据库选择显示所有表

WBOY
Release: 2016-05-26 15:22:05
Original
1289 people have browsed it

这里主要是讲关于php中数据库连接与数据库选择以及显示当前数据库所有表三个实用函数,有需要的朋友可以看看,php实例代码如下:

<?php
$phpsql_user = "root";
$phpsql_password = "root";
$phpsql_loc = "";
$phpsql_db = "";
function phpsql_connect($location, $username, $password) {
    global $phpsql_loc, $phpsql_user, $phpsql_password;
    if ($phpsql_user != $username || $phpsql_password != $password) phpsql_error("cannot access to phpsql!(wrong username/wrong password)");
    define(phpsql_loc, $location);
    $phpsql_loc = $location;
}
function phpsql_select_db($db) {
    global $phpsql_db;
    define(phpsql_db, $db);
    $phpsql_db = $db;
}
function phpsql_list_table() {
    global $phpsql_loc, $phpsql_db;
    $i = 0;
    if (!($handle = @opendir($phpsql_loc . "/" . $phpsql_db))) return 0;
    while (($file = readdir($handle)) !== false) {
        if ($file != "." && $file != "..") {
            $table[$i++] = $file;
        }
    }
    return $table;
}
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template