這個(gè)無(wú)關(guān)php。單純的SQL語(yǔ)法。

為桃源等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及桃源網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、桃源網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
mysql_query(" ALTER TABLE tablename ADD COLUMN colname type");
ALTER語(yǔ)法,更多SQL語(yǔ)法請(qǐng)查看
貨幣可以用Decimal(10,2)類型,但是建議直接乘以100以整數(shù)形式進(jìn)行存儲(chǔ),因?yàn)楹芏嗾Z(yǔ)言對(duì)浮點(diǎn)數(shù)運(yùn)算會(huì)有誤差。
mysql_connect('地址','用戶名','密碼');
mysql_select_db('數(shù)據(jù)庫(kù)名');
$sql = "ALTER TABLE `表名` ADD `列名` 數(shù)據(jù)類型";
mysql_query($sql);
?php
class MysqlManage{
/*創(chuàng)建數(shù)據(jù)庫(kù),并且主鍵是aid
* table 要查詢的表名
*/
function createTable($table){
$sql="CREATE TABLE IF NOT EXISTS `$table` (`aid` INT NOT NULL primary key)ENGINE = InnoDB;";
M()-execute($sql);
$this-checkTable($table);
}
/*
* 檢測(cè)表是否存在,也可以獲取表中所有字段的信息
* table 要查詢的表名
* return 表里所有字段的信息
*/
function checkTable($table){
$sql="desc `$table`";
$info=M()-execute($sql);
return $info;
}
/*
* 檢測(cè)字段是否存在,也可以獲取字段信息(只能是一個(gè)字段)
* table 表名
* field 字段名
*/
function checkField($table,$field){
$sql='desc `$table` $field';
$info=M()-execute($sql);
return $info;
}
/*
* 添加字段
* table 表名
* info 字段信息數(shù)組 array
* return 字段信息 array
*/
function addField($table,$info){
$sql="alter table `$table` add column";
$sql.=$this-filterFieldInfo();
M()-execute($sql);
$this-checkField($table,$info['name']);
}
/*
* 修改字段
* 不能修改字段名稱,只能修改
*/
function editField($table,$info){
$sql="alter table `$table` modify ";
$sql.=$this-filterFieldInfo($info);
M()-execute($sql);
$this-checkField($table,$info['name']);
}
/*
* 字段信息數(shù)組處理,供添加更新字段時(shí)候使用
* info[name] 字段名稱
* info[type] 字段類型
* info[length] 字段長(zhǎng)度
* info[isNull] 是否為空
* info['default'] 字段默認(rèn)值
* info['comment'] 字段備注
*/
private function filterFieldInfo($info){
if(!is_array($info))
return
$newInfo=array();
$newInfo['name']=$info['name'];
$newInfo['type']=$info['type'];
switch($info['type']){
case 'varchar':
case 'char':
$newInfo['length']=empty($info['length'])?100:$info['length'];
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOT NULL';
$newInfo['default']=empty($info['default'])?'':'DEFAULT '.$info['default'];
$newInfo['comment']=empty($info['comment'])?'':'COMMENT '.$info['comment'];
break;
case 'int':
$newInfo['length']=empty($info['length'])?7:$info['length'];
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOT NULL';
$newInfo['default']=empty($info['default'])?'':'DEFAULT '.$info['default'];
$newInfo['comment']=empty($info['comment'])?'':'COMMENT '.$info['comment'];
break;
case 'text':
$newInfo['length']='';
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOT NULL';
$newInfo['default']='';
$newInfo['comment']=empty($info['comment'])?'':'COMMENT '.$info['comment'];
break;
}
$sql=$newInfo['name']." ".$newInfo['type'];
$sql.=(!empty($newInfo['length']))?($newInfo['length']) .' ':' ';
$sql.=$newInfo['isNull'].' ';
$sql.=$newInfo['default'];
$sql.=$newInfo['comment'];
return $sql;
}
/*
* 刪除字段
* 如果返回了字段信息則說(shuō)明刪除失敗,返回false,則為刪除成功
*/
function dropField($table,$field){
$sql="alter table `$table` drop column $field";
M()-execute($sql);
$this-checkField($table,$filed);
}
/*
* 獲取指定表中指定字段的信息(多字段)
*/
function getFieldInfo($table,$field){
$info=array();
if(is_string($field)){
$this-checkField($table,$field);
}else{
foreach($field as $v){
$info[$v]=$this-checkField($table,$v);
}
}
return $info;
}
}
沒(méi)明白你的意思
你說(shuō)的是 表里的 行呢
還是 行 里面的 值呢
表里面的行,直接insert 一條就可以
行里的值用 update tablename set x = 101 where 別的條件 limit 1;
這個(gè)x是你要修改的字段,101是修改后的值,x以前是=1的,limit 1是只修改一條的意思。
分享名稱:php增加數(shù)據(jù)庫(kù)字段 php增加數(shù)據(jù)庫(kù)數(shù)據(jù)
網(wǎng)站路徑:http://chinadenli.net/article42/dojghhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站收錄、品牌網(wǎng)站設(shè)計(jì)、定制網(wǎng)站、標(biāo)簽優(yōu)化、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)