How do I check for the existence of a particular MySQL table using PHP? (Using an IF statement.)

1 Answer

Answer :

answer:I don’t know of a preexisting function, so here’s one I wrote real quick (untested): function checkTable ($table_name, $database_name) { $my_tables [equal] mysql_list_tables($database_name); while (list($foo) [equal] mysql_fetch_array($my_tables)) { if ($foo [equal][equal] $table_name) return true; } return false; } if (checkTable(“content”, “your_database”)) { // Table exists } else { // Table does not exist }

Related questions

Description : Anyone using Spry with PHP/MySQL in Dreamweaver CS3?

Last Answer : Why are you asking? Are you already using it, or wondering if it's a good choice of tools?

Description : Best tools to build a collaborative project site using only open-source Apache/Mysql/PHP tools

Last Answer : answer:We've used Trac for a few projects with success. Its not perfect but it is configurable and you can extend it. Of course its geared very much towards software development and I'm not sure ... a specific set of tracking and documenting and were glad we did later on in the development cycle.

Description : Error message when using PHP with MySQL.

Last Answer : Wow! Good luck with that!

Description : What are the best web sites to get help with Apache, PHP, and MySQL?

Last Answer : stackoverflow is the best site programming q & a site I know of. Looks like there is a fair amount of LAMP-related questions there.

Description : As a specialist PHP/MySQL programmer at my (not so fun to work at) job, what's my future?

Last Answer : It depends if you want to continue doing programming or not. If you have good people skills, and good business sense, you could get PMP certified, or learn VersionOne and move to the business ... business side. We also prize business analysts with SQL knowledge in order to manage data and metrics.

Description : If I already know basic PHP/MySQL, what else should I learn to use Google App Engine?

Last Answer : answer:I am not an expert, I just started reading up on this myself, but here are a couple of starting points on data storage. Rather than a separately maintained SQL database, ... .com/appengine/articles/datastore/overview.html http://code.google.com/appengine/docs/python/datastore/overview.html

Description : What is apache or perl or php or mySQL?

Last Answer : Apache, Perl, PHP, MySQL Seriously, Wikipedia does wonders. Also try searching with Google.

Description : PHP/MySQL question.... (please read on)

Last Answer : Have you looked through these?

Description : What is a good book for learning PHP and MySQL?

Last Answer : I’d start here: http://www.php.net/manual/en/ Get a feel for PHP, then buy books to fill in the gaps or get deeper into particular areas.

Description : How long does it take to learn PHP & MySQL?

Last Answer : The O’Reilly Head First book on this is great.

Description : Do you know webhosting server including with these details: free, about 1-2 gigabytes, php script OK, mysql OK, no adds on site?

Last Answer : Hosting a free Wordpress blog. Interesting. Did you try wordpress.com? Most hosts aren’t going to offer those serviced ad-free for free. I can’t think of a single one. Everyone needs a business model. And even if I found one, I certainly wouldn’t trust it for stability and security.

Description : Can someone please explain to me exactly how PHP, mySQL, Javascript, and HTML/CSS are related?

Last Answer : PHP is a serverside language, while JavaScript and mySQL are clientside languages. I think the difference is that PHP/HTML is the language used by the server to encode instructions for the web browser, ... have no idea whether it's accurate or not. I just started learning this stuff this week.

Description : Getting certified in PHP and MySQL?

Last Answer : I think Zend, the company behind PHP, has some kind of certification. Is this required for something? I’ve honestly never seen a job requiring a “certified” PHP programmer. Edit: This looks like it.

Description : Is there a PHP library or API that would let me quickly build survey questionnaires and dump the captured data to MySQL?

Last Answer : If you are familiar with LAMP and PHP, why not build a little CRUD application?

Description : Are there any resources that you can recommend for me to learn LAMP (Linux Apache MySQL Perl/Python/PHP?

Last Answer : I’m not educated in this type of stuff, but I did a little research and got these. http://lamphowto.com http://onlamp.com

Description : What is your favorite PHP/MySQL ecommerce application and why?

Last Answer : answer:

Description : GAE contains the several runtime environments including : JAVA, Python, _______ & a) C# & MySQL b) Net & Ruby c) PHP & GO d) Closure & Scala

Last Answer : PHP & GO

Description : What MySQL database admin app should I be using?

Last Answer : I use CocoaMySQL

Description : Add an ID column to an already existing MySQL table?

Last Answer : I’m not an expert on MySQL [@stewartwb?], but in SQLServer that works just fine. Add the column and set the identity property and it autogenerates. What happens when you try that in MySQL? Do you get an error? or does it just not populate?

Description : How to import a html table into mysql?

Last Answer : Do you have a link to the table? Unless somebody is aware of a script that I haven’t come across, the script would be specific to the table and shouldn’t be too hard to write.

Description : Write the code in python to read the contents of “number.csv” file consisting of data from a mysql table and print the data of the table -Technology

Last Answer : f = open('numbers.csv', 'r') with f:reader = csv.reader(f)for row in reader:for e in row:print(e)

Description : Is there a server-side utility that I can call from PHP to spell check a user's input from a text box?

Last Answer : There are a bunch of them out there. Here’s a PHP spell checker class.

Description : How would I check if an XML element exists in PHP?

Last Answer : Wrap it in an if that checks for the existence first if($status->item(0)) { $eventStatus = $status->item(0)>getAttributeNode( value )->value; } and run from there, I haven't actually run your ... and does just about everything you'll want (then you can use the DOM stuff to fill in the blanks)

Description : What Text/HTML/PHP editors support SVN check in/out?

Last Answer : answer:Eclipse with the subclipse plugin is cross-platform, has robust svn-support, and is free/open source. You'll want other plugins too, probably Aptana for the HTML/PHP. Komodo will do this ... /Comparison_of_text_editors. I'd say the top 3 you should play with are eclipse, komodo, and jedit.

Description : What takes more computing power, serving HTTP or MySQL?

Last Answer : this is not exactly my field, but i would say http has much more to do that mysql. with http you are loading everything, where mysql is just loading data. i guess it could depend on the site and whats on it, but for the most part http will be doing most the work.

Description : Does MySQL have a native counter function for its results?

Last Answer : I know that with PHP when you query the database and it returns any results it'll provide an array of results I think so you can loop through them and get the data from them, however nativly I don't ... and report what I find, if anything at all :) what langauge are you programming in by the way?

Description : Is there something wrong with my MySQL query?

Last Answer : answer:SELECT CONCAT_WS( ’ ’, first_name, last_name ) AS full_name, username, country, region, CONCAT_WS( ’, ’, region, country ) AS location FROM people HAVING full_name[equal]‘John Doe’ Damn! I’ve been awake for a long time. Silly me.

Description : What are the major differences between MySQL and SQLite?

Last Answer : answer:Okay, from what i've picked up from wikipedia and what I know, MySQL is a seperate server process and can be run standalone on a server and requires more resources then the likes of SQLite. It ... here hehe) It entirely depends on what you're using the database for, I hope this helps :)

Description : How do I do a MySQL Insert statement into 2 different tables?

Last Answer : sounds to me like two separate insert statements... or maybe i don't understand the question...

Description : Point out the wrong statement. a) Wolf Frameworks uses a C# engine and supports both Microsoft SQL Server and MySQL database b) Applications built in Wolf are 50-percent browser-based ... and multisource overlaid content c) Google applications are cloud-based applications d) None of the mentioned

Last Answer : Applications built in Wolf are 50-percent browser-based and support mashable and multisource overlaid content

Description : Point out the wrong statement. a) Wolf Frameworks uses a C# engine and supports both Microsoft SQL Server and MySQL database b) Applications built in Wolf are 50-percent browser-based ... and multisource overlaid content c) Google applications are cloud-based applications d) None of the mentioned

Last Answer : Applications built in Wolf are 50-percent browser-based and support mashable and multisource overlaid content

Description : Is there any difference in terms of performance to build my website's database using PostGreSQL than to built it using MySQL?

Last Answer : A few years back, the choice was between raw speed, in which case you chose MySQL, and features and reliability, in which case you chose PostgreSQL. (If you needed speed, features, and reliability, ... is what databases are built to do, but in older versions of MySQL there was simply no alternative.

Description : What is a PHP error?

Last Answer : It’s to do with encryption. PHP means Pretty High Privacy or something like that. IT means that the data sent was not encrypted. This might happen on a website that starts with https. What were you doing at the time?

Description : What is the most popular PHP framework available?

Last Answer : I’m lazy and will just answer the last question. I use CakePHP when I need too since I’m familiar with it and it gives me the least problems out of the ones I have used. But I avoid them and usually just do everything from scratch.

Description : Is it better to use single or double quotes when coding with PHP?

Last Answer : They’re actually interpreted differently. See here.

Description : Is there any way to edit php without code?

Last Answer : Nope. Because it’s more of a scripting language than a programming language like BASIC or C and than a mark up language like XHTML. PHP isn’t too hard to learn though (or so I’ve heard)

Description : What's the easiest way to learn how to code in CSS and PHP?

Last Answer : tizag.com

Description : PHP Gurus: What is the easiest way to generate a specified length string of random alpha characters?

Last Answer : answer:Well, this code will spit stuff out per your “For example” Not sure what alpha characters are though… Check it here.

Description : Which of the following information not included in memory table? A) The allocation of main memory to process. B) The allocation of secondary memory to process C) Any information needed to manage virtual memory D) Any information about the existence of file

Last Answer : D) Any information about the existence of file

Description : Using a PHP page to post "blog" entries on my website.

Last Answer : answer:It shouldn't be too hard- you'll probably want to apply the CSS to the page that is retrieving and displaying the information, not the page you use to enter it. Whatever code is generating your ... CSS classes, id tags, and DIVs to. It's hard to get specific without actually seeing the code.

Description : What is the advantage of using a PHP Framework?

Last Answer : answer:The advantage is speed and support. With any framework, you are relying on the work of others to speed up your development process. Because so much has been built in, you don't have to ... development outfits write something once and then reuse it across projects. It's the same type of model.

Description : Is sending email through an SMTP server on the same machine as my web application more or less efficient than using PHP mail()?

Last Answer : I’m confused by your question. Wouldn’t PHP mail() ultimately be using whatever SMTP server you use to send mail?

Description : Which of the following statements is false   You can make a website without using HTML   You can make a website without using PHP   You can make a website without using CSS   You can make a website without using Javascript

Last Answer :  You can make a website without using HTML

Description : I posted a sale on craigslist for a dining table. I just received an offer. The Buyer will pay using a certified check drawn from a US bank. Should I go through with the Sale? Is this a Scam? What are the precautions I should take?

Last Answer : answer:Looks like scam. Often times, a check can be successfully deposited in your bank only to be rejected later. So confirmation in that case can be a fleeting thing. Same goes for money orders. If you have ... bank, you could cash his check there. Then you've got cash in hand and are good to go.

Description : MySQL help!

Last Answer : answer:You spelled “propeller” wrong, for one thing. Table SERVICE_REQUEST has a primary key, SERVICE_ID, which is a DECIMAL field. In your attempt to load the table with the error record, the secondary key value you attempted to insert for SERVICE_ID, ‘7’ is a CHAR value. That’s a show-stopper.

Description : Empty entries in a mysql/php5 site database,... why?

Last Answer : How are you migrating the database? What are you using to export and import?

Description : MySQL order by primary key, put one row on top.

Last Answer : answer:If you can guarantee that there is only one or zero active records select * from presets order by active asc, id asc

Description : How can I create an ordered list of the most common substrings inside of a MySQL varchar column?

Last Answer : SQL is definitely not my specialty but you can use regular expressions within your select statement is this something you want to pull on the fly each time though? It seems like as your data set grows it ... ve got me wondering if I can write one SQL statement for it though, let me take a look.

Description : MySQL Sort by every other row?

Last Answer : Couldn’t you just grab the males in a query and do the same for the females. Then loop through them in PHP. If that made any sense.

Description : How can I search for a specific column name in MySQL?

Last Answer : SELECT table_name, column_name from information_schema.columns WHERE column_name LIKE 'Name';