php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26644 file function works wrong
Submitted: 2003-12-17 05:50 UTC Modified: 2003-12-17 11:55 UTC
From: doris dot hahn at landover dot de Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 4.3.4 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: doris dot hahn at landover dot de
New email:
PHP Version: OS:

 

 [2003-12-17 05:50 UTC] doris dot hahn at landover dot de
Description:
------------
Hallo everybody,
I don't know if the problem I have is a bug or a feature in the new version.
I have a PHP skript which reads a text file into an array using the file function. This array than is worked up with an  array_walk. The text file contains SQL-statements which should be given to mysql_query. These statements contain apostrophes to mark character strings in SQL. 
In fewer PHP versions the statements are read as they are in the text file, in the new version back slashes are added to the apostrophes by the file function. So I get an error from mysql, naturally. 
Is this slash adding a new feature of the file function or is it a bug? If it is a new feature, which special characters are slash added too? The documentation says nothing about that. And there is no answer from the support side.
Thank you for your help.
Doris Hahn

Reproduce code:
---------------
<? 
  function sql_query_script ($zeile) {

    echo "$zeile<br>";

    return;
  }	// end function sql_query_script

//****  Main  *****************************************
	$filnam = "x.txt";
	$script = file ($filnam);
	array_walk ($script, "sql_query_script");
?>



Expected result:
----------------
The text file x.txt contains the following line:
INSERT INTO Currency VALUES (0,'EUR',1000000)

I expect the script to output the following line:
INSERT INTO Currency VALUES (0,'EUR',1000000)

but the script outputs the following line:
INSERT INTO Currency VALUES (0,\'EUR\',1000000)




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-17 11:20 UTC] iliaa@php.net
Do you have magic_quotes_runtime enabled?
 [2003-12-17 11:50 UTC] doris dot hahn at landover dot de
yes, magic_quotes_runtime is switched on
 [2003-12-17 11:55 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Turn them off and the problem will go away. When this ini setting is enabled any input processed by PHP (such as reading a file) will effectively go through addslashes().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 06:01:29 2024 UTC