Check if MySQL table exists or not [duplicate]

Updated mysqli version: if ($result = $mysqli->query(“SHOW TABLES LIKE ‘”.$table.”‘”)) { if($result->num_rows == 1) { echo “Table exists”; } } else { echo “Table does not exist”; } Original mysql version: if(mysql_num_rows(mysql_query(“SHOW TABLES LIKE ‘”.$table.”‘”))==1) echo “Table exists”; else echo “Table does not exist”; Referenced from the PHP docs.

How to check if a directory/file/symlink exists with one command in Ruby

The standard File module has the usual file tests available: RUBY_VERSION # => “1.9.2” bashrc = ENV[‘HOME’] + ‘/.bashrc’ File.exist?(bashrc) # => true File.file?(bashrc) # => true File.directory?(bashrc) # => false You should be able to find what you want there. OP: “Thanks but I need all three true or false” Obviously not. Ok, try … Read more

MongoDB: How to query for records where field is null or not set?

If the sent_at field is not there when its not set then: db.emails.count({sent_at: {$exists: false}}) If it’s there and null, or not there at all: db.emails.count({sent_at: null}) If it’s there and null: db.emails.count({sent_at: { $type: 10 }}) The Query for Null or Missing Fields section of the MongoDB manual describes how to query for null … Read more

What is easier to read in EXISTS subqueries? [closed]

Intuitive is …EXISTS (SELECT * .. because you really don’t care The only keyword of importance is EXISTS The choice of …EXISTS (SELECT 1 .. perpetuates the general myths and superstitions around EXISTS (eg comments on the MySQL docs). ANSI standard says “doesn’t matter” It’s more interesting to understand that EXISTS is a semi-join.

SQL – IF EXISTS UPDATE ELSE INSERT INTO

Create a UNIQUE constraint on your subs_email column, if one does not already exist: ALTER TABLE subs ADD UNIQUE (subs_email) Use INSERT … ON DUPLICATE KEY UPDATE: INSERT INTO subs (subs_name, subs_email, subs_birthday) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE subs_name = VALUES(subs_name), subs_birthday = VALUES(subs_birthday) You can use the VALUES(col_name) function in the … Read more