The thing that i want to do is to check if there is a same row and if not to insert a new row to the table.
In that case, how can i use if not exists
?
INSERT INTO `facebook` (`ID`,`fb_id`,`label_id`,`page_ids`,`token`)
SELECT NULL, '". $session['id'] ."', '$id', '', '". $access_token ."'
FROM DUAL
WHERE NOT EXISTS (SELECT 'x' FROM facebook WHERE label_id = '$id')
I think FROM DUAL
is optional, but I'm an Oracle guy. :)
User Insert Into to ignore duplicates:
INSERT IGNORE INTO `facebook`
SET `ID` = null,
`fb_id` = '". $session['id'] ."',
`label_id` = '$id',
`page_ids`='',
`token`='". $access_token ."';
You can use the INSERT IGNORE INTO ...
syntax. When using this, duplicate key errors are treated as warnings and the statement will return without having inserted the affected row.