PDA

View Full Version : updating database error


tamayolo
10-31-03, 02:05 PM
i was installed phpmyadmin on my host, then i was created an database and upload info into tables, but now when i tried to make it again updating info on a table, phpmyadmin toldme that mysql version donīt support command for updating table information.
like this:

Error
SQL-query :

LOAD DATA LOCAL INFILE '/var/tmp/phpIT1k9N' INTO TABLE `catalogoprod` FIELDS TERMINATED BY ';' ENCLOSED BY '"'


MySQL ha dicho:


The used command is not allowed with this MySQL version

how i can update urgent info into a table?

HalfaBee
10-31-03, 06:44 PM
You will have to write a little php script to do the job.

This is an untested script, but it should be pretty close.
You will need to make sure that the table has exactly the same fields as the data.

HalfaBee


$file = 'datafile.txt';
$enclosed = '"';
$terminated=';';
$table = 'table_name';

mysql_connect( 'server','user','passwd' );
mysql_select_db( 'db_name' );

$data = file( $file ) or die( "No file $file" );
foreach( $data as $s ) {
$d = explode( $termintaed , $s );
$d = str_replace( $enclosed,'',$d );
$sql = "INSERT into $table VALUES ( ";
foreach( $d as $v )
$sql .= "'$v'";
$sql .= ")";
mysql_query( $sql ) or die( mysql_error()."in this SQL $sql );

}

Nino
10-31-03, 08:04 PM
Originally posted by HalfaBee
You will have to write a little php script to do the job.

This is an untested script, but it should be pretty close.
You will need to make sure that the table has exactly the same fields as the data.

HalfaBee


$file = 'datafile.txt';
$enclosed = '"';
$terminated=';';
$table = 'table_name';

mysql_connect( 'server','user','passwd' );
mysql_select_db( 'db_name' );

$data = file( $file ) or die( "No file $file" );
foreach( $data as $s ) {
$d = explode( $terminated , $s );
$d = str_replace( $enclosed,'',$d );
$sql = "INSERT into $table VALUES ( ";
foreach( $d as $v )
$sql .= "'$v'";
$sql .= ")";
mysql_query( $sql ) or die( mysql_error()."in this SQL $sql );

}


There is a typo in that script. The second instance of the variable $terminated.
I changed it for you :)

tamayolo
11-4-03, 06:23 PM
i was write an " that missing on:

mysql_query( $sql ) or die( mysql_error()."en esta secuencia sql $sql" );

this canīt fix my problem, i was read line per line every fields and my data have the same columns, but script in page showme:

Column count doesn't match value count at row 1 in this sql INSERT into catalogoprod VALUES ( '1''..''29-100''GRUPO AJOVER''AJOCINDU 1.80 MARFIL''19504''\r\n ')

this is an example of fields:

"1;..;29-100;GRUPO AJOVER;AJOCINDU 1.80 MARFIL;19504"

and in the table have the same columns.

some body help me!!!

or i can connect to database and update data over any other way?

HalfaBee
11-4-03, 06:47 PM
Updated script.

<?php

$file = 'datafile.txt';
$enclosed = '"';
$terminated=';';
$table = 'table_name';

mysql_connect( 'server','user','passwd' );
mysql_select_db( 'db_name' );

//$data[] = "1;..;29-100;GRUPO AJOVER;AJOCINDU 1.80 MARFIL;19504\r\n";
$data = file( $file );
foreach( $data as $s ) {
$d = explode( $terminated , trim($s) );
$d = str_replace( $enclosed,'',$d );
$sql = "INSERT into $table VALUES ( ";
foreach( $d as $v )
$sql .= "'$v',";
$sql = preg_replace( '/,$/','',$sql );
$sql .= ")";

mysql_query( $sql ) or die( mysql_error()."in this SQL $sql );
// echo $sql;
}
?>