\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);
}
//-SETUP-WERT-FELDER
$query_data = „„“. („“, „„, $csvdata) implodieren. ““ „;
// SETUP EINE FRAGE
$sql = „ERSETZEN IN myTable ($query_cols) BEWERTET ($query_data)“;
// LASSEN DIE FRAGE HIER…. LAUFEN
$res = mysql_query ($sql);
//, WENN mysql_query () FALSCHES ZURÜCKBRINGT, ERHALTEN DIE STÖRUNGS-GRÜNDE
//-MANN-SEITE: http://us.php.net/manual/en/function.mysql-error.php
wenn (! $res)
{
$errmsg = mysql_errno (). ''. mysql_error ();
Echo „ FRAGEN-AUSFALLEN: „;
Echo „ $sql „;
sterben ($errmsg);
}
}
//-ERSCHEINEN, WELCHES DIE ZAHL REIHEN VERARBEITETE
Echo „ SÄTZE VERARBEITETEN $counter \ n ";
|