如何用php判斷mysql資料庫裡某張表是否存在

時間 2021-10-14 22:24:01

1樓:

<?php

$dsn = 'mysql:host=localhost;dbname=庫名';

$pdo = new pdo($dsn, '使用者名稱', '密碼');

$sql = 'show tables';

$res = $pdo->query($sql);

$res = $res->fetchall(2);

foreach ($res as $val)// echo '';

// var_dump($tables);

if (!in_array('想要查詢的表名', $tables))

2樓:一騎當後

<?php

/*查詢資料庫是否存在功能

$sql:查詢資料庫的sql語句

$find_table:需要檢查的表名

*/mysql_connect('localhost','root','2260375') or die('can\'t not connect database');

if((int)check_table_is_exist('show databases;','test')==1)

else

function check_table_is_exist($sql,$find_table)

unset($result,$row);

mysql_close();

/*開始判斷表是否存在*/

if(in_array($find_table,$database))

else

}?>

如何用php判斷mysql資料庫裡某張表是否存在????

3樓:匿名使用者

<?php

/*查詢資料庫是否存在功能

$sql:查詢資料庫的sql語句

$find_table:需要檢查的表名

*/mysql_connect('localhost','root','2260375') or die('can\'t not connect database');

if((int)check_table_is_exist('show databases;','test')==1)

else

function check_table_is_exist($sql,$find_table)

unset($result,$row);

mysql_close();

if(in_array($find_table,$database))

else

}?>

php中怎樣使用mysql查詢語句判斷欄位中是否存在指定資料

4樓:匿名使用者

不要bai用mysql_fetch_object()這個函式來判斷,du這個返回來的是個陣列;一zhi般情況下dao是這麼來判斷的專:$query="select * from ".$tablepre.

"common_members"." where username ='".$_post['reg_username'].

"'";$result=mysql_query($query,$link);$num = mysql_num_rows($result); //取得結果集中行的數屬目if($num)

5樓:匿名使用者

用mysql_num_rows()吧,bai

判斷>0則說明註冊了的,

du否則就沒註冊。zhi

daomysql_fetch_object()一般是用來版 輸出 內容的,而不是權進行判斷的。-----------------------<?php

mysql_connect("hostname", "user", "password");

mysql_select_db("mydb");

$result = mysql_query("select * from mytable");

while ($row = mysql_fetch_object($result))

mysql_free_result($result);

?>

6樓:匿名使用者

其實很簡單的!!有個函式是is_array();他可以判斷是不是陣列,只要查詢返回是陣列的話!!就是被註冊了!

php mysql 怎麼判斷某個表的字段是否存在 20

7樓:

不要用mysql_fetch_object()這個函式來判斷,這個返回來的是個陣列;一般情況下是這麼來判斷的:$query="select * from ".$tablepre.

"common_members"." where username ='".$_post['reg_username'].

"'";$result=mysql_query($query,$link);$num = mysql_num_rows($result); //取得結果集中行的數目if($num)

PHP插入MySQL資料後變成亂碼

編碼方式不一樣,你資料庫的編碼是gb2312,你頁面的也應該是gb2312 還有一個地方就是連線資料庫的地方加句 mysql query set names gb2312 牛志向 資料庫 程式還有瀏覽器的編碼方式要一樣,要麼都是gb2312,要麼都是utf 8,等等 插入之前要加上下面的語句 mys...

如何用php呼叫外部介面json資料

阿不吃de哥柯禾 兩種比較簡單的方法 1 使用curl url http www.x.com ch curl init curl setopt ch,curlopt url,url curl setopt ch,curlopt returntransfer,1 curl setopt ch,curl...

如何用php修改資料庫中的資料

舉例如下 建立userinfo update.php頁面用於查詢使用者資訊,先顯示資訊,在修改 先通過get獲取使用者編號查詢使用者資訊 sql select from user info where user id get userid result mysql query sql,con if ...