The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
SQL Query - Check Existance of Data/Column before making changes.
Hi Guys... I have 2 questions.
1) During an install I'm using "CREATE TABLE IF NOT EXISTS" to create tables but there's no similar option for ALTER TABLE so what is the best way to check if a column already exists in the users table? 2) During the same install I'm using INSERT INTO to populate a table... how do I check if the table is empy first? THX! Right now I'm just ignoring errors using $vbulletin->db->hide_errors(); but I'd rather do a proper check. |
#2
|
||||
|
||||
Quick answers ;
1. Use DESCRIBE table and loop through the results looking for the fieldname. 2. Use SELECT * FROM table LIMIT 1 If the number of rows returned = 1 then you have records in the table. |
#3
|
|||
|
|||
[high]* DaNIEL MeNTED wishes the quick answers were long.
[/high] Off to go look for code. Hmm... found and modified this for columns. Is there a cleaner way to do it? PHP Code:
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|