Fabio_Siqueira Posted February 9, 2016 Share Posted February 9, 2016 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 https://forums.phpfreaks.com/topic/300765-how-to-pass-the-array-value-to-the-function/ Share on other sites More sharing options...
benanamen Posted February 9, 2016 Share Posted February 9, 2016 Before even dealing with your question, you need to stop using deprecated Mysql code and stop suppressing errors with @. You need to use PDO with prepared statements. Link to comment https://forums.phpfreaks.com/topic/300765-how-to-pass-the-array-value-to-the-function/#findComment-1530926 Share on other sites More sharing options...
Fabio_Siqueira Posted February 9, 2016 Author Share Posted February 9, 2016 (edited) Yes I know that!! Actually i'm using Mysqli Edited February 9, 2016 by Fabio_Siqueira Link to comment https://forums.phpfreaks.com/topic/300765-how-to-pass-the-array-value-to-the-function/#findComment-1530930 Share on other sites More sharing options...
Jacques1 Posted February 10, 2016 Share Posted February 10, 2016 Actually i'm using Mysqli Then post the updated code. Link to comment https://forums.phpfreaks.com/topic/300765-how-to-pass-the-array-value-to-the-function/#findComment-1530965 Share on other sites More sharing options...
Barand Posted February 10, 2016 Share Posted February 10, 2016 Closing this topic as you have reposted it in another of the forums Link to comment https://forums.phpfreaks.com/topic/300765-how-to-pass-the-array-value-to-the-function/#findComment-1530973 Share on other sites More sharing options...
Recommended Posts