guarana1 Posted May 29, 2015 Report Share Posted May 29, 2015 (edited) Boas malta, estou a tentar passar uma tabela da bd para um ficheiro csv. Estou a ter um erro de "mysql_fetch_assoc() expects parameter 1 to be source, bollean given in..." <?php // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings fputcsv($output, array('Column 1', 'Column 2', 'Column 3')); // fetch the data mysql_connect('localhost', 'root', ''); mysql_select_db('teste'); $rows = mysql_query('SELECT field1,field2,field3 FROM table'); // loop over the rows, outputting them while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row); ?> Edited May 29, 2015 by guarana1 Link to comment Share on other sites More sharing options...
apocsantos Posted May 29, 2015 Report Share Posted May 29, 2015 Boa tarde, A query está a ser executada ? Pelo código do erro, leva a crer que a query não está a ser executada. Cordiais cumprimentos, Apocsantos "A paciência é uma das coisas que se aprendeu na era do 48k" O respeito é como a escrita de código, uma vez perdido, dificilmente se retoma o habito" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now