mysql_list_tables 在php5應該支持的,再說,向下兼容的啊幫助文檔:例 1397. mysql_list_tables() 例子/b?php
翼城網(wǎng)站建設公司創(chuàng)新互聯(lián)公司,翼城網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為翼城成百上千提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務好的翼城做網(wǎng)站的公司定做!
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
print 'Could not connect to mysql';
exit;
}
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
print "Table: $row[0]\n";
}
mysql_free_result($result);
?
每個表都應該有區(qū)分
比如結(jié)尾_1
_2
_3
,循環(huán)sql
替換表結(jié)尾的表示,
規(guī)律看你的表名了
這個先連接數(shù)據(jù)庫,然后調(diào)用,代碼如下:
$dbhost?=?'localhost:3306';??//?mysql服務器主機地址
$dbuser?=?'root';????????????//?mysql用戶名
$dbpass?=?'123456';??????????//?mysql用戶名密碼
$conn?=?mysqli_connect($dbhost,?$dbuser,?$dbpass);
if(!?$conn?){
die('Could?not?connect:?'?.?mysqli_error());
}
echo?'數(shù)據(jù)庫連接成功!';mysqli_close($conn);
$sql=mysql_query("select?*??from?wx_agent_orders?where?id=1");
$row=mysql_query($conn,$sql);
while($r=mysql_fetch_array($row)){
echo?$r['sendcontent']
}
這是最基礎的php獲取mysql方法了,希望采納
親,你的想法有問題,這是不符合要求的。
數(shù)據(jù)庫中有很多的表,表中有字段。因此你不可能查詢數(shù)據(jù)庫中的id和news,而是只能在特定的表上查詢。同時sql語法也要求
select
fields
from
table_name而不是db_name哦。
舉例來說,保存新聞的表名字是news,
位于數(shù)據(jù)庫
my_test_db中,那么應該
$con = mysql_connect("127.0.0.1", "123", "123");
mysql_select_db('my_test_db', $con);
$sql = "select id, news from news";后面的代碼就一樣了
mysql_connect('地址','用戶名','密碼');
mysql_select_db('數(shù)據(jù)庫名');
$sql = "ALTER TABLE `表名` ADD `列名` 數(shù)據(jù)類型";
mysql_query($sql);
function add($name, $type, $size, $defaultvalue = '', $options = '', $title = '', $note = '', $formtype = '', $inputtool = '', $inputlimit = '', $enablehtml = 1, $enablelist = 1, $enablesearch = 0)
{
if(!in_array($type, $this-fieldtypes) || $this-exists($name)) return FALSE;
$size = intval($size);
$fieldsize = $type == 'varchar' ? min($size, 255) : ($type == 'int' ? min($size, 10) : 0);
$fieldtype = strtoupper($type);
if($fieldsize) $fieldtype .= "( $fieldsize )";
$this-db-query("ALTER TABLE $this-table ADD $name $fieldtype NOT NULL");
$this-db-query("INSERT INTO ".TABLE_FIELD."(tablename,name,type,size,defaultvalue,options,title,note,formtype,inputtool,inputlimit,enablehtml,enablelist,enablesearch) VALUES('$this-table','$name','$type','$size','$defaultvalue','$options','$title','$note','$formtype','$inputtool','$inputlimit','$enablehtml','$enablelist','$enablesearch')");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
function edit($fieldid, $type, $size, $defaultvalue = '', $options = '', $title = '', $note = '', $formtype = '', $inputtool = '', $inputlimit = '', $enablehtml = 1, $enablelist = 1, $enablesearch = 0)
{
if(!in_array($type, $this-fieldtypes)) return FALSE;
$fieldid = intval($fieldid);
$field = $this-get_info($fieldid);
$name = $field['name'];
$size = intval($size);
$fieldsize = $type == 'varchar' ? min($size, 255) : ($type == 'int' ? min($size, 10) : 0);
$fieldtype = strtoupper($type);
if($fieldsize) $fieldtype .= "( $fieldsize )";
$this-db-query("ALTER TABLE `$this-table` CHANGE `$name` `$name` $fieldtype NOT NULL");
$this-db-query("UPDATE ".TABLE_FIELD." SET title='$title',note='$note',type='$type',size='$size',defaultvalue='$defaultvalue',options='$options',formtype='$formtype',inputtool='$inputtool',inputlimit='$inputlimit',enablehtml='$enablehtml',enablelist='$enablelist',enablesearch='$enablesearch' WHERE fieldid=$fieldid");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
function delete($fieldid)
{
$fieldid = intval($fieldid);
$r = $this-db-get_one("SELECT name FROM ".TABLE_FIELD." WHERE fieldid=$fieldid");
if(!$r) return FALSE;
$name = $r['name'];
$this-db-query("ALTER TABLE $this-table DROP $name");
$this-db-query("DELETE FROM ".TABLE_FIELD." WHERE fieldid=$fieldid");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
db數(shù)據(jù)庫類去下個phpcms里面的就是上面的是自定義字段的操作函數(shù)