note 92669 modified in function.mysql-field-flags by danbrown
| From: | danbrown@php.net | Date: | Mon, 03 Aug 2009 16:42:14 +0000 |
| Subject: | note 92669 modified in function.mysql-field-flags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159033@lists.php.net to get a copy of this message | ||
To really backup the database values, I made a little changement :
My code really looks like bomas 's code, but there is an important diffence :
<?php
$nbc = mysql_num_fields($req_table);
while ($ligne = mysql_fetch_array($req_table))
{
$insertions = "INSERT INTO $table VALUES(";
for ($i=0; $i<$nbc; $i++)
{
if ( $i > 0 ) $insertions .= ", ";
if ( !isset($ligne[$i]))
$insertions .= "NULL";
else
$insertions .= "'" . mysql_real_escape_string($ligne[$i]).
"'";
}
$insertions .= ");";
$dumpsql[] = $insertions;
}
?>
$dumpslq is the variable where I put the insertion orders before writting them in a text file.
Before, I test that the values if not NULL into the field because it is the only way to make the
difference, for example for string text fields, between NULL values and empty strings.
If you don't make this test, you should find empty string instead of NULL values when you do
the backup.
--was--
To really backup the database values, I made a little changement :
My code really looks like bomas 's code, but there is an important diffence :
$nbc = mysql_num_fields($req_table);
while ($ligne = mysql_fetch_array($req_table))
{
$insertions = "INSERT INTO $table VALUES(";
for ($i=0; $i<$nbc; $i++)
{
if ( $i > 0 ) $insertions .= ", ";
//
/// The difference is here, the test on NULL value
//
if ( !isset($ligne[$i]))
$insertions .= "NULL, ";
else
$insertions .= "'".mysql_real_escape_string($ligne[$i]) .
"', ";
}
Before, I test that the values if not NULL into the field because it is the only way to make the
difference, for example for string text fields, between NULL values and empty strings.
If you don't make this test, you should find empty string instead of NULL values when you do
the backup.
http://php.net/manual/en/function.mysql-field-flags.php