Created
August 20, 2014 14:09
-
-
Save bytefade/6da6bf564dd9f5dbdbd5 to your computer and use it in GitHub Desktop.
Insert plano exemplo otimizado
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Excel/reader.php'; | |
$data = new Spreadsheet_Excel_Reader(); | |
$data->setOutputEncoding('CP1251'); | |
$data->read('exemplo.xls'); | |
//constantes com os dados do db. | |
define('DB_NOME', '*******'); | |
define('DB_USUARIO', '********'); | |
define('DB_SENHA', '***********'); | |
define('DB_HOST', '*******'); | |
//conecta ao MySQL. | |
$conexao = mysql_connect(DB_HOST, DB_USUARIO, DB_SENHA) or die ('Erro ao conectar ao MySQL: ' . mysql_error()); | |
//conectar ao db 'flashInteracao'. | |
$conexaoDb = mysql_select_db(DB_NOME, $conexao) or die ('Erro ao conectar a base de dados: ' . mysql_error()); | |
$userData = array(); | |
for ($x = 1; $x <= count($data->sheets[0]["cells"]); $x++) { | |
$userData[] = '( | |
"' .$data->sheets[0]["cells"][$x][1] . '", | |
"' .$data->sheets[0]["cells"][$x][2] . '", | |
"' .$data->sheets[0]["cells"][$x][3] . '", | |
"' .$data->sheets[0]["cells"][$x][4] . '", | |
"' .$data->sheets[0]["cells"][$x][5] . '", | |
"' .$data->sheets[0]["cells"][$x][6] . '", | |
"' .$data->sheets[0]["cells"][$x][7] . '", | |
"' .$data->sheets[0]["cells"][$x][8] . '", | |
"' .$data->sheets[0]["cells"][$x][9] . '", | |
"' .$data->sheets[0]["cells"][$x][10] . '", | |
"' .$data->sheets[0]["cells"][$x][11] . '")'; | |
} | |
$query = 'INSERT INTO rcsaude_tabela_preco (`tiulo`, `faixa1`, `faixa2`, `faixa3`, `faixa4`, `faixa5`, `faixa6`, `faixa7`, `faixa8`, `faixa9`, `faixa10`) VALUES' . implode(',', $userData); | |
$result = mysql_query($query); | |
// trata erro | |
if (!$result) { | |
die("erro: ".mysql_error()); | |
} | |
// Verifique o resultado | |
echo 'Consulta válida: ' . $query . '<br>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment