I have a database with this structure:
ID -- INT(11) -- Primary
post -- BIT(1)
This is just 2 columns , the database is way bigger. I've developed a plugin that needs to export this database to a .csv file using this code:
if (!$this->conn->connect_error)
{
$out_file = dirname(__DIR__,1)."/uploads/{$dir}/test.csv";
$out_file = str_replace("\\","/",$out_file);
$result = $this->conn->query("SELECT * INTO OUTFILE '{$out_file}' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM module");
if ($result==true)
return 1;
else
return 0;
}
Then, when i check the .csv generated file, in the post column (BIT value) it shows nothing where 0 and this sign where is 1 []
. then, I need to import it back into mysql table, by reading the file and just inserting the lines using a prepared statement like this:
while (($data = fgetcsv($file,0,",")) !== FALSE)
{
//now we should insert
//prepared stmt
$ID = $data[0];
$Prod_ID = $data[1];
$desc = $data[2];
$desc2 = $data[3];
$tip_id = $data[4];
$pret = $data[5];
$post = $data[6];
$prioritat = $data[7];
$views = $data[8];
$info = $data[9];
$img = $data[10];
$rgb = $data[11];
$stock = $data[12];
$date = $data[13];
$prep->execute();
}
But as you guess, this leads to an error because the data in .csv file from post column is not valid. I can not change the Bit to TINYINT, so my guess is that i need to somehow convert bit to int in the export .csv file and then convert the int to bit back when inserting. How can I do this?