Jump to content


Photo

need help regarding bulk insert in php


  • Please log in to reply
1 reply to this topic

#1 m31hu1

m31hu1
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 21 October 2006 - 09:47 PM

Hi all, I'm new to this forum... and need help regarding a project that i am doing.
I'm trying to let sql store data from a text file, but the data won't display...
what am i missing here? Your help is greatly appreciated.

create table
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}// Create database
if (mysql_query("CREATE DATABASE bulkdb",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}

// Create table in bulkdb database
mysql_select_db("bulkdb", $con);
$sql = "CREATE TABLE Bulktable
(
fileID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(fileID),
FileName varchar(15),
Directory varchar(100)
)";


mysql_query($sql,$con);

?>

bulk insert
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bulkdb", $con);
$bulkinsert = "BULK INSERT Bulktable
FROM 'test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)";

if ($bulkinsert){
echo "inserted";
}
else{
echo "not inserted";}

mysql_close($con);
?>


bulk select
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bulkdb", $con);
$result = mysql_query("SELECT * FROM bulktable");

mysql_close($con);


echo "<table><tr><th colspan=\"3\">Results</th></tr><tr>";

while($row = mysql_fetch_array($result))
{
$img = $row['Directory'] . "" . $row['FileName'];
echo "<td><img src=\"$img\" height=\"60\" width=\"60\"></td>";

}

?>

test.txt
1.jpg,http://localhost/images/
2.jpg,http://localhost/images/
3.jpg,http://localhost/images/
4.jpg,http://localhost/images/
5.jpg,http://localhost/images/
6.jpg,http://localhost/images/
7.jpg,http://localhost/images/
8.jpg,http://localhost/images/

Regards,
Mei Hui

#2 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 21 October 2006 - 09:58 PM

you can't create a Database with mysql_query

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users