I have my SQL query working fine in PHPMyAdmin but can't get it work with PHP. Let's say I have this query:
SELECT Login, Firstname, Lastname, Company INTO OUTFILE 'c:\\users.txt' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'
FROM `Users` WHERE Company = 'SID';
I would like to call my query from a web page with a click. I did 2 files fonction.php and form.php as follow. For fonction.php
<?php
function connectMaBase(){
$base = mysql_connect ('localhost', 'root', '');
mysql_select_db ('CCPayment', $base) ;
}
?>
And for form.php I have this
<?php
include("fonction.php");
?>
<html>
<head><title>Pages de requetes SQL </title></head>
<body>
<h1> Requete SQL </h1>
<form name="sqlquery" method="post" action="form.php">
<input type="submit" name="valider" value="Go"/>
</form>
<?php
if (isset ($_POST['valider'])){
connectMaBase();
$sql = "SELECT Login, Firstname, Lastname, Company INTO OUTFILE \'c:\\\\Users.txt\' FIELDS TERMINATED BY \',\' LINES TERMINATED BY \'\\r\\n\' \n"
. "FROM `OptiOutput` WHERE Company = \'SID\'";
mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());
mysql_close();
}
?>
</body>
</html>
I'm a beginner and could not find what is wrong in the code.
Thanks for your help.
Aucun commentaire :
Enregistrer un commentaire