Hi,
I am new to PHP and currently working on data migration from Oracle to MySQL using PHP . I am currently facing problem while inserting(Oracle to MySQL) for a particular (Oracle) table whose column has CLOB content of 253 Bytes.
The error is: Catchable fatal error: Object of class OCI-Lob could not be converted to string in C:\wamp\www\demo\InsertMySQL_Version1.php on line 68
Below is the function that dynamically creates the insert query for MySQL:
function formatInsertQuery($tablename, $insertconn, $row)
{
$str1= "insert into $tablename values (";
$result= mysql_query("SELECT * FROM $tablename");
$ncols = mysql_num_fields($result);
for ($i = 0; $i < $ncols; $i++) // column index starts from 0
{
$column_type = mysql_field_type($result, $i);
if($column_type=="int" || $column_type=="float" || $column_type=="decimal" || $column_type=="real")
{
$str2 .= $row[$i]. "," ;
}
else if($column_type=="varchar" || $column_type=="char" || $column_type=="longtext" || $column_type=="string" || $column_type=="blob")
{
$replacestr= str_replace("'","''",$row[$i]); // this is the line where error occurs
$str2 .= "'" . $replacestr . "'" . "," ;
}
}
$str3=substr($str2, 0, strlen($str2)-1);
$str4= $str1.$str3.")";
return $str4;
}
The error occurs at the line : $replacestr= str_replace("'","''",$row[$i]);
This code works fine with other datatypes like int, varchar and float.
Can anyone pls help me to sort out this issue? Thanks in Advance.
Regards,
Prakash