\n"; //READABILITY FOR var_dump()
// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??"; // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";
// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo " NO DB CONNECTION: ";
echo " $errmsg ";
}
// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo " NO DB SELECTION: ";
echo " $errmsg ";
die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES
// THE NAMES OF OUR COLUMNS
$query_cols = "name, price, Description";
// TEST DATA URL
$csv = "http://path/to/my.csv";
$fpo = fopen($csv, 'r');
if (!$fpo ) die('CRUMP');
// SET A ROW COUNTER
$counter = 0;
// KEEP TRACK OF ROWS THAT HAVE THE WRONG NUMBER OF FIELDS
$errors = array();
// LOOP THROUGH THE CSV RECORDS PERFORMING CERTAIN TESTS
while (!feof($fpo))
{
$counter++;
// GET A RECORD
$csvdata = fgetcsv($fpo);
// SKIP OVER EMPTY ROWS
if (empty($csvdata)) continue;
// ESCAPE THE INFORMATION FOR USE IN THE QUERY
foreach ($csvdata as $ptr => $value)
{
$csvdata [$ptr] = mysql_real_escape_string ($value);
}
CAMPOS DE VALOR DE LA DISPOSICIÓN DE //
$query_data = ““”. implode (“”, ““, $csvdata). ”” “;
// FIJÓ UNA PREGUNTA
$sql = “SUBSTITUYEN EN myTable ($query_cols) VALORAN ($query_data)”;
// FUNCIONA CON LA PREGUNTA AQUÍ….
$res = mysql_query ($sql);
// SI el mysql_query () VUELVE FALSO, CONSIGUE LAS RAZONES del ERROR
PÁGINA DE HOMBRE DE //: http://us.php.net/manual/en/function.mysql-error.php
¡si (! $res)
{
$errmsg = mysql_errno (). ''. mysql_error ();
eco “ FALL DE LA PREGUNTA: “;
eco “ $sql “;
morir ($errmsg);
}
}
DEMOSTRACIÓN DE // QUE EL NÚMERO DE FILAS PROCESÓ
eco “ Los EXPEDIENTES PROCESARON $counter \ n ";
|