|
|
| |
1. INSERT zero issue |
|
Reply |
|
|
 Robert Frew | 2010-04-01 19:50:16 |
If you insert into the database using a value of zero, nothing is inserted into the database at all for that field.
IE:
$first_name = 'Rob';
$f1 = '1';
$f2 = '0';
$dbLink = new DB();
$aResult = $dbLink->query('INSERT INTO app_data (first_name,f1,f2) VALUES (?,?,?)',$first_name,$f1,$f2);
The table shows:
+----------+--+--+
|first_name|f1|f2|
+----------+--+--+
|Rob |1 | |
+----------+--+--+ |
| |
2. Re: INSERT zero issue |
|
Reply |
|
|
 Camilo Sperberg | 2010-04-01 20:43:41 - In reply to message 1 from Robert Frew |
That seems to happen with the "BIT" fields and the command line mysql client.
If you do something like this:
$aRes = $dbLink->query('SELECT * FROM probadita');
echo '<pre>';
print_r($aRes);
echo '</pre>';
you would be able to see something like this:
[0] => Array
(
[my_boolean] => 0
)
[1] => Array
(
[my_boolean] => 1
)
Where 0 == false and 1 == true.
You should insert boolean values as '1' for true and '0' as false (WITH the single quotes).
IE:
$aRes = $dbLink->query('INSERT INTO t1 VALUES (?)','0'); // Inserting false
$aRes = $dbLink->query('INSERT INTO t1 VALUES (?)','1'); // Inserting true
Greetings ! |
| |
3. Re: INSERT zero issue |
|
Reply |
|
|
 Robert Frew | 2010-04-01 22:43:12 - In reply to message 2 from Camilo Sperberg |
Thanks for your reply.
I thought I was inserting using single quotes as you can see in the example. Is this not the correct way to do this?
Thanks for your help. |
| |
4. Re: INSERT zero issue |
|
Reply |
|
|
 Robert Frew | 2010-04-01 22:47:28 - In reply to message 2 from Camilo Sperberg |
Here is what it returns:
Array
(
[0] => Array
(
[first_name] => Rob
[f1] => 1
[f2] =>
)
)
|
| |
5. Re: INSERT zero issue |
|
Reply |
|
|
 Robert Frew | 2010-04-01 22:51:07 - In reply to message 2 from Camilo Sperberg |
Also, if I use the following:
$f2 = 0; //integer
instead of:
$f2 = '0'; //string
It enters into the database as 0 just fine. However, I am retrieving these values from a POST form so the numeric values come through as strings. |
| |
6. Re: INSERT zero issue |
|
Reply |
|
|
 Robert Frew | 2010-04-01 23:29:35 - In reply to message 2 from Camilo Sperberg |
| And last thing... if I don't use your wrapper and I call the mysqli directly, it works just fine using the same variables and information. |
| |
7. Re: INSERT zero issue |
|
Reply |
|
|
 Camilo Sperberg | 2010-04-02 15:54:37 - In reply to message 4 from Robert Frew |
| is your MySQL field a BIT field? If not, what field type is it? Which PHP/MySQL version are you using? |
|