Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 03:07 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default Mysql

hi

$value = 'INSERT INTO `decoration` VALUES ('DPR882', 'Porcelain Donkey', '2.88', '23.00', '36', '', '0.75', '', '0', '');';

$query = mysql_query("$value");

is it possible????

Thanks
Regards

 
Old April 27th, 2005, 03:18 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

should be:

INSERT INTO decoration_table (col1,col2,col3,col4,col5,col6) VALUES (val1, val2, val3, val4, val5, val6);


e.g.


mysql> INSERT INTO employee_data
    -> (f_name, l_name, title, age, yos, salary, perks, email)
    -> values
    -> ("Manish", "Sharma", "CEO", 28, 4, 200000,
    -> 50000, "[email protected]");




----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
 
Old April 27th, 2005, 03:29 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thanks For Reply

I try to
1st
//mysql connection

2nd
//open file read it;
$file = $_SERVER['DOCUMENT_ROOT'].'/file';
$fileOpen = fopen($file.'/Decoration.txt', 'r') or die("Cannot Open the File");

$content = fgets($fileOpen, 999);
while(!feof)
{
    $query = mysql_query($content) or die("BYE");
}

to write my data from file
it same as the way that phpMyAdmin has it.

the code above would not do it.
can you guys help me for that.

Thanks
Regards

 
Old April 27th, 2005, 06:52 PM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is it the sql that isn't working or the php?



 
Old April 27th, 2005, 07:00 PM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The sql should look something like:

INSERT INTO tableName
SET columnName = 'value1',
    columnName2 = 'value2'

I wouldn't deal with opening a text file if you don't need to. It is easier just to assign the sql to a variable.

Are you using Apache or something else...this can affect your connection type.

 
Old April 28th, 2005, 11:43 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thank you all for the reply

Here is the story:
I had website that was on SBS Server. I changed the server 2 days ago, but before I cancel my account with SBC I Exported all the tables in my database with phpMyAdmin. The files has a .sql extension.
Now I have my website on yahoo server so I want to import those file to my new mysql.
I used phpMyAdmin to import the file, but I got an Error, and seems phpMyAdmin could not find any file. So I come up with an idea to convert the .sql file to .txt file (The query in .sql file is INSERT) open and read the file with php. so each line of .txt file has INSERT query. so I used the code that I gave u guys to do it but each time I try to do it, it give me an Error (The custom Error that i made)

//connect to mysql
//open and read file
while(!feof)
{
  $content = fgets($fileOpen, 999); //$content carry INSERT statment
  $qarey = mysql_query($content) or die("Cennot Do it");
}

So I guess the logic is ok, but I have no Idea whats wrong with it.
any Idea?
And again thank you guys for reply.

Thanks
Regards

 
Old April 28th, 2005, 01:51 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hi
Finally I found the problem.
As I said I export data from mysql server using phpMyAdmin.
The problem was when phpMyadmin wrote the file, it wrote it like

INSERT INTO 'table_name' VALUES(....);
it put ; at the end so when i read the first line with php from file and put it in $content, $content has the value with ;.
so when i used mysql_query() it gives me an error, so when I delete ; at the end of each line from file it works perfectly.

Thanks
Regards







Similar Threads
Thread Thread Starter Forum Replies Last Post
Why not MySQL ??? mysticav BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 August 18th, 2006 04:32 PM
MySQL 5.0 dparsons MySQL 0 May 11th, 2006 08:32 AM
mysql help benzspida MySQL 1 April 6th, 2006 04:31 AM
MYSQL hkurtulus BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 November 23rd, 2005 05:59 PM
MySQL 4.0 or 4.1 allang MySQL 1 January 10th, 2004 10:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.