php mysql table exists function

this checks if a mysql table already exists in the selected database and returns true or false
// setup database connection
$db = new mysqli($db_host$db_user$db_pass$db_name);

// function
function table_exists($table) {
$table $db->mysql_real_escape_string($table);
$sql "SHOW TABLES LIKE '$table' ";
$result $db->query($sql);
$num 0;
$num mysqli_num_rows($result);
$num 0) {

// usage
$my_table_name "my_table_name";
table_exists($table $my_table_name)) {
"$my_table_name exists :)";
} else {
"$my_table_name does not exist :(";

Other Items in php
Related Search Terms
Page Views

This page has been viewed 564 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
therock Somewhere along this crazy road I learned (often times the hard way) the most important things I can do is be authentic, trust my gut, be the hardest worker in the room, celebrate the mistakes, be a grateful man and always remember that it's nice to be important, but it's more important to be nice.
The Rock