Help to write a script that will fetch some elements from the database and write data to a file in CSV format, or at least a function that prints to a file?
2 answers
<?php ... $get_fileds = mysql_query('SELECT id, product_name, product_imgproduct_text FROM i_block_elements'); $f = fopen('file.csv', 'w'); while ($ar = mysql_fetch_row($get_fields)) fputcsv($f, $ar); fclose($f); ?>
Well, on top of the connection to the database, do not forget to register if Cho:
<?php $conn = mysql_connect(«localhost», «jon», «secret») or die(«Could not connect to MySQL.»); mysql_close($conn); ?>
- I have a _konsnew database and the i_block_elements table in it, so from it you need to select only id in the file, product_name, product_imgproduct_text explain how pliz - psix
- SELECT t.id, t.product_name, t.product_imgproduct_text FROM i_block_elements t Everything is clear here? Corrected the answer. - Artyomich
- Warning: mysql_fetch_row (): the following is a valid MySQL result resource in /home/konser0/public_html/import.php on line 13 - psix
- As I understand it, the problem is related to the lack of data or tables in the MySQL database, rewrite the query as in the answer without using aliases. - Artyomich
- rewrote, does not help. gives the same error. There are tables in the database, and there is data too. login, pass I register everything correctly .... = ( - psix
|
For example:
SELECT * INTO OUTFILE 'filename.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM tablename;
|