$con = mysql_connect("localhost","ccp","ccp2000"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Drop database $query = mysql_query("DROP DATABASE ccp",$con); if (!$query) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Create database $query = mysql_query("CREATE DATABASE ccp",$con); if (!$query) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Create table mysql_select_db("ccp", $con); //"Wooldridge",1,"660","8397912","","MO","Wooldridge" $sql = 'CREATE TABLE dialupnumbers ( cityID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(cityID), cityname varchar(20), country varchar(1), areacode varchar(3), telephone varchar(7), extra varchar(30), state varchar(2), city varchar(20) )'; // Execute query mysql_query($sql,$con); $row = 1; if (($handle = fopen("ccpaccess.phl", "r")) !== FALSE) { while (($data = fgetcsv($handle, 255, ",")) !== FALSE) { $num = count($data); //echo "

$num fields in line $row:

\n"; $row++; //for ($c=0; $c < $num; $c++) { // echo $data[$c] . "
\n"; //INSERT INTO dialupnumbers VALUES ('city',1,'816','5551234','extra','city','state'); $sql = "INSERT INTO dialupnumbers (cityname, country, areacode, telephone, state, city)\nVALUES ( "; $sql2 = "'".$data[0]."','".strval($data[1])."','".$data[2]."','".$data[3]."','".$data[5]."','".$data[6]."');"; //echo "$sql $sql2
\n"; mysql_query($sql.$sql2,$con); //} //echo "--------------------------------------------------------------------------
\n"; } fclose($handle); } mysql_close($con); ?>