SlideShare a Scribd company logo
CSV
NOE POMPOSO
CESAR RUIZ
Tic 91
Exportar CSV
<?php
$db_host = 'localhost';//SERVIDOR
$db_usuario = 'root';//USUARIO
$db_password = 'nones';//PASS
$db_basedatos = 'programacion';//BASE DE DATOS
$db_tabla = 'categoria';//TABLA PARA SU RESPALDO
$$nombre_fichero = 'categoria.csv';//NOMBRE DEL ARCHIVO
$dblink = mysql_connect($db_host, $db_usuario, $db_password) or die("No puede conectar " .
mysql_error());
mysql_select_db($db_basedatos) or die("No puede conectar.");//CONEXION
$result = mysql_query("SHOW COLUMNS FROM ".$db_tabla."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$salida_cvs .= $row['Field'].",";
$i++;
}
}
$salida_cvs .= "n";
$values = mysql_query("SELECT * FROM ".$db_tabla."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$salida_cvs .= $rowr[$j].", ";
}
$salida_cvs .= "n";
}
header("Content-type: application/vnd.ms-excel");//DESCARGA DE ARCHIVO
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$nombre_fichero.".csv");
print $salida_cvs;
exit;
?>
Importar
<?php
//connectar base de datos
$connect = mysql_connect("localhost","root","nones");
mysql_select_db("programacion",$connect); //sseleccionar base de datos
//
if (isset($_FILES['csv']['size'])){
if ($_FILES['csv']['size'] > '0') {
//obtener archivo csv
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//recooje archivo csv y e inserta en la base de datos
do {
if ($data[0]) {
mysql_query("INSERT INTO marcas (MARCA,ACTIVO) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//
header('Location: import.php?success=1'); die;
} }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>
<body>
<?php if (!empty($_GET['success'])) { echo "<b>Your file has been imported.</b><br><br>"; }
//generic success notice ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file: <br />
<input name="csv" type="file" id="csv" />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
csv
Interfaz de selección
Selección de csv
Backup csv

More Related Content

What's hot

Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016
Marcel Schmitz
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
Oleg Zinchenko
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2
Michał Kruczek
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy code
Michał Kruczek
 
php Slideshare
php Slidesharephp Slideshare
php Slideshare
Jason Liao
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
Nur Fadli Utomo
 
Php talk
Php talkPhp talk
Php talk
Jamil Ramsey
 
Php redirect code
Php redirect codePhp redirect code
Php redirect codeVineet Garg
 
Coding for php with mysql
Coding for php with mysqlCoding for php with mysql
Coding for php with mysql
Rajamanickam Gomathijayam
 
hotel managment
hotel managmenthotel managment
hotel managmentMelk Biks
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
Yusuke Wada
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)webhostingguy
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
純生 野田
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
純生 野田
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Yusuke Wada
 

What's hot (19)

Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016
 
M.php
M.phpM.php
M.php
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy code
 
php Slideshare
php Slidesharephp Slideshare
php Slideshare
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
 
Php talk
Php talkPhp talk
Php talk
 
Php redirect code
Php redirect codePhp redirect code
Php redirect code
 
Coding for php with mysql
Coding for php with mysqlCoding for php with mysql
Coding for php with mysql
 
hotel managment
hotel managmenthotel managment
hotel managment
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Facebook
FacebookFacebook
Facebook
 
kazumich@acmscamp2010spring
kazumich@acmscamp2010springkazumich@acmscamp2010spring
kazumich@acmscamp2010spring
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 

Viewers also liked

komposit Serat coir / kelapa
komposit Serat coir / kelapakomposit Serat coir / kelapa
komposit Serat coir / kelapaJohn Rambo
 
Telephoneetiquette 090928161625-phpapp01
Telephoneetiquette 090928161625-phpapp01Telephoneetiquette 090928161625-phpapp01
Telephoneetiquette 090928161625-phpapp01rgrecula
 
komposit serat Rami
komposit serat Rami komposit serat Rami
komposit serat Rami John Rambo
 
Design Undangan
Design Undangan Design Undangan
Design Undangan
Eko S
 
Hasil+plpg+angkatan+27 28+(tanjung)
Hasil+plpg+angkatan+27 28+(tanjung)Hasil+plpg+angkatan+27 28+(tanjung)
Hasil+plpg+angkatan+27 28+(tanjung)
Eko S
 
Biomedik kesmas otot
Biomedik kesmas ototBiomedik kesmas otot
Biomedik kesmas ototSuparjan
 
Practica json
Practica jsonPractica json
Practica json
Nones Pomposo
 

Viewers also liked (8)

komposit Serat coir / kelapa
komposit Serat coir / kelapakomposit Serat coir / kelapa
komposit Serat coir / kelapa
 
Telephoneetiquette 090928161625-phpapp01
Telephoneetiquette 090928161625-phpapp01Telephoneetiquette 090928161625-phpapp01
Telephoneetiquette 090928161625-phpapp01
 
komposit serat Rami
komposit serat Rami komposit serat Rami
komposit serat Rami
 
Practica Rss.
Practica Rss.Practica Rss.
Practica Rss.
 
Design Undangan
Design Undangan Design Undangan
Design Undangan
 
Hasil+plpg+angkatan+27 28+(tanjung)
Hasil+plpg+angkatan+27 28+(tanjung)Hasil+plpg+angkatan+27 28+(tanjung)
Hasil+plpg+angkatan+27 28+(tanjung)
 
Biomedik kesmas otot
Biomedik kesmas ototBiomedik kesmas otot
Biomedik kesmas otot
 
Practica json
Practica jsonPractica json
Practica json
 

Similar to Practica csv

The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 
Practical MySQL.pptx
Practical MySQL.pptxPractical MySQL.pptx
Practical MySQL.pptx
HussainUsman4
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
Wez Furlong
 
与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库
YUCHENG HU
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Rifat Nabi
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
Razvan Raducanu, PhD
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
CynthiaKendi1
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
SULTHAN BASHA
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
Razvan Raducanu, PhD
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
Vineet Kumar Saini
 

Similar to Practica csv (20)

The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Practical MySQL.pptx
Practical MySQL.pptxPractical MySQL.pptx
Practical MySQL.pptx
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
My shell
My shellMy shell
My shell
 
Php (1)
Php (1)Php (1)
Php (1)
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 

Recently uploaded

Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 

Recently uploaded (20)

Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 

Practica csv

  • 2. Exportar CSV <?php $db_host = 'localhost';//SERVIDOR $db_usuario = 'root';//USUARIO $db_password = 'nones';//PASS $db_basedatos = 'programacion';//BASE DE DATOS $db_tabla = 'categoria';//TABLA PARA SU RESPALDO $$nombre_fichero = 'categoria.csv';//NOMBRE DEL ARCHIVO $dblink = mysql_connect($db_host, $db_usuario, $db_password) or die("No puede conectar " . mysql_error()); mysql_select_db($db_basedatos) or die("No puede conectar.");//CONEXION $result = mysql_query("SHOW COLUMNS FROM ".$db_tabla.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $salida_cvs .= $row['Field'].","; $i++; } } $salida_cvs .= "n"; $values = mysql_query("SELECT * FROM ".$db_tabla.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $salida_cvs .= $rowr[$j].", "; } $salida_cvs .= "n"; } header("Content-type: application/vnd.ms-excel");//DESCARGA DE ARCHIVO
  • 3. header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$nombre_fichero.".csv"); print $salida_cvs; exit; ?> Importar <?php //connectar base de datos $connect = mysql_connect("localhost","root","nones"); mysql_select_db("programacion",$connect); //sseleccionar base de datos // if (isset($_FILES['csv']['size'])){ if ($_FILES['csv']['size'] > '0') { //obtener archivo csv $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //recooje archivo csv y e inserta en la base de datos do { if ($data[0]) { mysql_query("INSERT INTO marcas (MARCA,ACTIVO) VALUES ( '".addslashes($data[0])."',
  • 4. '".addslashes($data[1])."' ) "); } } while ($data = fgetcsv($handle,1000,",","'")); // // header('Location: import.php?success=1'); die; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET['success'])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" />
  • 5. <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> csv Interfaz de selección Selección de csv