从config.ini访问数据库连接和查询表数据的数据库信息

时间:2017-08-17 08:21:38

标签: php mysql

我正在使用共享主机。这里我创建了config.ini文件 在<properties> <!-- default properties --> <jvm.args>-XX:MaxMetaspaceSize=64m -Xloggc:logs/gc_%p_%t.log</jvm.args> <derby.version>USE_REQUIRED_JRE8_DERBY_VERSION</derby.version> </properties> ... <profiles> <profile> <activation> <jdk>1.7</jdk> </activation> <properties> <jvm.args>-XX:MaxPermSize=64m -Xloggc:logs/gc.log</jvm.args> <derby.version>10.12.1.1</derby.version> </properties> </profile> </profiles> 中包含连接信息。

  1. 在默认文件夹中复制了/home/kkits996/private/config.inidbconnection.php 当我运行dbconcheck来检查dbconnection并检索表数据时 它没有显示表格cruduser的获取结果 表中的回显值未显示。

    dbconnect.php

    dbconcheck.php

    dbconcheck.php

    <?php
    function db_connect() {
    
        // Define connection as a static variable, to avoid connecting more than once 
        static $connection;
    
        // Try and connect to the database, if a connection has not been established yet
        if(!isset($connection)) {
            // Load configuration as an array. Use the actual location of your configuration file
            //    $config = parse_ini_file('/home/kkits996/private/config.ini'); 
            $connection = mysqli_connect($config['servername'],$config['username'],$config['password'],$config['dbname']);
        }
    
        // If connection was not successful, handle the error
        if($connection === false) {
            // Handle error - notify administrator, log to a file, show an error screen, etc.
            return mysqli_connect_error(); 
        }
        return $connection;
    }
    
    // Connect to the database
    $connection = db_connect();
    
    // Check connection
    if ($connection->connect_error) {
        die("Connection failed: " . $connection->connect_error);
    }
    ?> 
    

0 个答案:

没有答案