每個(gè)表都應(yīng)該有區(qū)分
創(chuàng)新互聯(lián)建站是一家專業(yè)提供坡頭企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、HTML5建站、小程序制作等業(yè)務(wù)。10年已為坡頭眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。
比如結(jié)尾_1
_2
_3
,循環(huán)sql
替換表結(jié)尾的表示,
規(guī)律看你的表名了
$data=array();
$sql = "show fields from table";//最主要是這SQL得到全表信息
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
$data[]=$row['Field'];
}
$data數(shù)組就是字段名,count($data)就是字段數(shù)。
其實(shí)很簡(jiǎn)單啦.
?
$sql = "show fields from [TABLE]";
$data=array();
$query = mysql_query( $sql , $link );
while($row=mysql_fetch_array($query, MYSQL_ASSOC )){
array_push($data,$row);
}
print_R( $data );
?
主要是運(yùn)行.$sql = "show fields from [TABLE]"這句sql語(yǔ)句就可以了.能得到表全部信息.當(dāng)然了count( $data )就是字段個(gè)數(shù).
mysql_connect("localhost","root","") or die("登陸數(shù)據(jù)庫(kù)失敗");
mysql_select_db("iPad") or die("連接數(shù)據(jù)庫(kù)失敗");
mysql_query("set names utf8");
$sql = "ALTER TABLE `表名` ADD `字段名` 數(shù)據(jù)類型";
mysql_query($sql);
mysql_list_tables 在php5應(yīng)該支持的,再說(shuō),向下兼容的啊幫助文檔:例 1397. mysql_list_tables() 例子/b?php
$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);
?
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ù)庫(kù)類去下個(gè)phpcms里面的就是上面的是自定義字段的操作函數(shù)