doujiyuan0211 2016-04-09 14:12
浏览 146
已采纳

使用define()时未定义的变量错误

Using PHP 5.4 I am getting 'Notice: Undefined variable: sqliteDatabase in test.php on line 9'

Code:

<?php

//Set The Database Name, No Other Editing Of This File Should Be Done
 define("sqliteDatabase", "PlayerVsPlayerDatabase" );

 //Nothing Below Needs Touched
 date_default_timezone_set('UTC');

 if(!file_exists("${sqliteDatabase}.sqlite3")) {

    try {

        // Create (connect to) SQLite database in file
        $file_db = new PDO("sqlite:${sqliteDatabase}.sqlite3");
  • 写回答

1条回答 默认 最新

  • drzil26260 2016-04-09 14:21
    关注

    Change

    if(!file_exists("${sqliteDatabase}.sqlite3")) {
    

    to

    if(!file_exists(sqliteDatabase.".sqlite3")) {
    

    A constant should be called without single and double quotes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?