Jump to content

[problem]with some code

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Zero_Cool

Zero_Cool

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
function check_if_exist_file()

{

	if(!isset('config.php'))

	{

		die("SomeThing Is Wrong");

	}

	else(isset('config.php'))

	{

		define(DB_SERVER,"localhost");

		define(DB_USER,"DarkWoulf");

		define(DB_PASS,"1993");

		define(DB_NAME,"MuOnline");

	}

}
how can it be fixed please:)
ok i think i fixed it but need to know for 100% if the fix is correct
function check_if_exist_file()

{

	if(exist_file('config.php'))

	{

		die("SomeThing Is Wrong");

	}

	elseif(exist_file('config.php'))

	{

		define(DB_SERVER,"localhost");

		define(DB_USER,"DarkWoulf");

		define(DB_PASS,"1993");

		define(DB_NAME,"MuOnline");

	}

}


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
The correct function would be file_exists. If you look on the PHP resources (i.e. filesystem functions PHP: Filesystem Functions - Manual) you will find a breadth of functions to work with files.

You can as well type php.net/(function name here) to access its usage page as a shortcut, there are some neat resources online for PHP.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Zero_Cool

Zero_Cool

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
and one more thing is it possible for php to id if sql is installed or not ?

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200

Zero_Cool said:

and one more thing is it possible for php to id if sql is installed or not ?

You can check if they have the MySQL module loaded, in case they have set it up themselves:
if( !extension_loaded("mysql") ) {
   //MySQL not compiled with PHP, or not loaded
}
Although rarely it is not installed or bundled, so you can simply check if it can be connected to with mysql_connect(). The manual says it returns false on failure so you can check for this.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users