Jump to content

How to pass the array value to the function


Fabio_Siqueira

Recommended Posts

Hello guys!!

I want to build a function that read and save csv file in MySql.

 

The problem is that I can't pass the while array in function 'cause i want to change the variable $sql sometimes just to reduce my code in the future.

 

Ex:

function connect(){

@mysql_connect("localhost", "root", "");

mysql_select_db("school");

}

 

function import($sql=null){

 

$filename = $_GET['file'];

$openfile = fopen($filename, "r");

while(($row = fgetcsv($openfile,2048,";"))!==FALSE) {

 

 

mysql_query($sql) or die(mysql_error());

 

 

}

 

 

fclose($openfile);

}

 

$report = "Insert into table (DocumentoSD,Descricao,Cod_Client,Cliente) values('$row[0]','$row[1]','$row[2]','$row[3]')";

 

connect();

Import($report);

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.