-1

This is the code that I am currently using, but it's not working:

$param=$_GET['param'];
echo $param;
$query =file_get_contents($param);
Frits
  • 7,341
  • 10
  • 42
  • 60
fidha
  • 21
  • 6
  • 1
    **What is not working?** You are just loading a file - you need to do some action on it if you want SQL to "execute". – samiles May 23 '17 at 07:05
  • you need to use database driver as [mysql](http://php.net/mysqli) to do that – hassan May 23 '17 at 07:06
  • 1
    `file_get_contents` just __gets contents of a file__ – u_mulder May 23 '17 at 07:10
  • Uhm this isn't SQL... – WasteD May 23 '17 at 07:10
  • Actually I want to get as $query =file_get_contents("D:\MyScript.sql"); Here I want to pass this location from c#. – fidha May 23 '17 at 07:13
  • 1
    Please **edit your question** to explain what you are trying to do. The more details you provide the more likely you are to get a helpful answer. – APC May 23 '17 at 07:18
  • this is the result while running. "D:\Myscript.sql" Warning: file_get_contents("D:\\Myscript.sql"): failed to open stream: Invalid argument – fidha May 23 '17 at 07:25
  • @fidha are you running the webserver on your local computer? Altough, even if you are, you might have access issues too. – Sentinel May 23 '17 at 07:51
  • yes,am using local computer webserver for this.. http://localhost:5445/RunPhp/create.php?action=ExecuteScript&file="D:\Myscript.sql" – fidha May 23 '17 at 08:25
  • $query =file_get_contents($param); i need instead of param $query =file_get_contents("D:\Myscript.sql"); to execute ?any solutions plz – fidha May 23 '17 at 08:57
  • //Warning: file_get_contents("D:\Myscript.sql"): failed to open stream: Invalid argument in C:\xampp\htdocs\RunPhp\create.php – fidha May 23 '17 at 10:21

1 Answers1

0

According to your comment

Actually I want to get as $query =file_get_contents("D:\MyScript.sql"); Here I want to pass this location from c#

you should just read the content from the file with some kind of filereader and then execute the file with a instance of your db. I'm not pretty sure why you wrote "execute the script by php" and your comment says "pass the location from c#" but the base solution should be the same.

  • $query =file_get_contents($param); i need instead of param. $query =file_get_contents("D:\Myscript.sql"); to execute ?any solutions plz – fidha May 23 '17 at 09:15
  • Maybe this one can help you https://stackoverflow.com/questions/4027769/running-mysql-sql-files-in-php – Dominik Mayrhofer May 23 '17 at 09:30
  • $param=$_GET['file']; echo $param; $query =file_get_contents($param);//here i need $query =file_get_contents("D:\Myscript.sql"); $sqlArray = explode(';',$query ); – fidha May 23 '17 at 10:20
  • //Warning: file_get_contents("D:\Myscript.sql"): failed to open stream: Invalid argument in C:\xampp\htdocs\RunPhp\create.php – fidha May 23 '17 at 10:20
  • I think your problem is using the double quotes at your path. If you use them you should put "D:\\Myscript.sql" and if you don't want to use them use single quotes like 'D:\Myscript.sql' – Dominik Mayrhofer May 23 '17 at 10:33
  • Even if i ignore the fact that it seems i can't get it plain again (what i actually don't want to do at this point) i don't get it working to encrypt a password and decrypt it using the password and the hash. – Dominik Mayrhofer May 23 '17 at 10:43
  • ("D:\Myscript.sql" )this path getted from c# by passed a string and it is call in php code as $param,but while calling this $query =file_get_contents($param),not opening..! but $query =file_get_contents("D:\MyScript.sql") this is working . but i need this php code for many times so passing strings is good for me ,but it is not working – fidha May 23 '17 at 10:55