Как из php вставить в оракловую таблицу запись в поле с типом long raw?
Добрый день, нужно вставить средствами php строку из текстового файла в таблицу оракла в поле с типом данных long raw. Никогда не работал с таким типом, если кто сталкивался, подскажите как быть...
Код:
bool oci_execute ( resource $stmt [, int $mode] )
взял из справки по 5 РНР
<?php
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=substr($line,$p+1);
$q=OCIParse($c, "update TABLE1 set COLUMN2=".$st." where COLUMN1=".$id);
OCIExecute($c, OCI_DEFAULT);
};
OCIlogoff($c);
?>
и получаю ошибку ORA-01741 и ворнинг
Warning: ociexecute(): supplied resource is not a valid oci8 statement resource
Код:
OCIExecute($c, OCI_DEFAULT);
а надо
Код:
$stmt = oci_parse($conn, "insert into scott.hallo
values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
oci_execute($stmt, OCI_DEFAULT);
values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
oci_execute($stmt, OCI_DEFAULT);
приблизительно так...
Когда же справку внимательно читать будем ???
Здесь берём нормальную справку по РНР
подкорректировал запрос,
<?php
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=substr($line,$p+1);
$q=OCIParse($c, "update TABLE1 set COLUMN2=:st where COLUMN1=".$id);
oci_bind_by_name($q, ':st', $st);
$r= OCIExecute($q, OCI_DEFAULT);
if (!$r) {
$e = oci_error($q);
echo convert_cyr_string($e['message'],'d','w');
}
};
OCIlogoff($c);
?>
теперь получаю другую ошибку
Warning: ociexecute() [function.ociexecute]: ORA-01465: ҐўҐа® § ¤ ® иҐбв ¤ж вҐаЁз®Ґ зЁб«® in longraw.php on line 14
ORA-01465: неверно задано шестнадцатеричное число
Warning: ociexecute() [function.ociexecute]: ORA-01461: ¤®ЇгбЄ Ґвбп ЇаЁўп§Є LONG § 票п в®«мЄ® ¤«п § ҐбҐЁп ў бв®«ЎҐж LONG in longraw.php on line 20
ORA-01461: допускается привязка LONG значения только для занесения в столбец LONG
Код:
<?php
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=substr($line,$p+1);
$strlength = strlen($st);
for($i=0; $i<$strlength; $i++){
$returnval .= dechex(ord(substr($st, $i, 1)));
}
$st=$returnval;
$q=OCIParse($c, "update TABLE1 set COLUMN2=:st where COLUMN1=".$id);
oci_bind_by_name($q, ':st', $st);
$r= OCIExecute($q, OCI_DEFAULT);
if (!$r) {
$e = oci_error($q); // For oci_execute errors pass the statementhandle
echo convert_cyr_string($e['message'],'d','w');
}
};
OCIlogoff($c);
?>
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=substr($line,$p+1);
$strlength = strlen($st);
for($i=0; $i<$strlength; $i++){
$returnval .= dechex(ord(substr($st, $i, 1)));
}
$st=$returnval;
$q=OCIParse($c, "update TABLE1 set COLUMN2=:st where COLUMN1=".$id);
oci_bind_by_name($q, ':st', $st);
$r= OCIExecute($q, OCI_DEFAULT);
if (!$r) {
$e = oci_error($q); // For oci_execute errors pass the statementhandle
echo convert_cyr_string($e['message'],'d','w');
}
};
OCIlogoff($c);
?>
Так ведь у меня COLUMN2 и есть типа LONG RAW ! что здесь не так?
oci_bind_by_name()
то вам станет ясно в чём ваша ошибка
Код:
<?php
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=(substr(rtrim($line),$p+1));
$q=OCIParse($c, "update TABLE1 set COLUMN2=:st where COLUMN1=".$id);
oci_bind_by_name($q, ':st', $st,-1,OCI_B_BIN);
$r= OCIExecute($q, OCI_DEFAULT);
if (!$r) {
$e = oci_error($q); // For oci_execute errors pass the statementhandle
echo convert_cyr_string($e['message'],'d','w');
}
oci_free_statement($q);
};
OCIlogoff($c);
?>
$c=OCILogon("user", "passwd", "BBB") ;
$lines=file('C:\222.txt');
foreach ($lines as $line){
$p=strpos($line,"+");
$id=substr($line,0,$p);
$st=(substr(rtrim($line),$p+1));
$q=OCIParse($c, "update TABLE1 set COLUMN2=:st where COLUMN1=".$id);
oci_bind_by_name($q, ':st', $st,-1,OCI_B_BIN);
$r= OCIExecute($q, OCI_DEFAULT);
if (!$r) {
$e = oci_error($q); // For oci_execute errors pass the statementhandle
echo convert_cyr_string($e['message'],'d','w');
}
oci_free_statement($q);
};
OCIlogoff($c);
?>
Цитата:
Note:
The LONG RAW datatype is provided for backward compatibility with existing applications. For new applications, use the BLOB and BFILE datatypes for large amounts of binary data.
Oracle also recommends that you convert existing LONG RAW columns to LOB columns. LOB columns are subject to far fewer restrictions than LONG columns. Further, LOB functionality is enhanced in every release, whereas LONG RAW functionality has been static for several releases.
The LONG RAW datatype is provided for backward compatibility with existing applications. For new applications, use the BLOB and BFILE datatypes for large amounts of binary data.
Oracle also recommends that you convert existing LONG RAW columns to LOB columns. LOB columns are subject to far fewer restrictions than LONG columns. Further, LOB functionality is enhanced in every release, whereas LONG RAW functionality has been static for several releases.