十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
update table set field=concat(' ', field, '072110003') where field='072110001';
創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站設計、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務淮安,10余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:028-86922220
應該是
update table set field=concat_ws(' ', field, '072110003') where field='072110001';
或者
update table set field=concat(field, ' ', '072110003') where field='072110001';
對于需要一次添加多個值,并且都用' '隔開的話,用第二條語句比較方便。 一次只用一個的話,concat比較簡單而且不同數(shù)據(jù)庫通用。
?php
$jsonStr?=?file_get_contents("test.json");
$jsonStr?=?str_replace("var?goodsData=[","[",$jsonStr);
$jsonStr?=?str_replace("];","]",$jsonStr);
$jsonData?=?json_decode($jsonStr,true);
$data?=?array();
$data['a']?=?'test';
$data['b']?=?'12133';
array_push($jsonData,$data);
$json_string?=?"var?goodsData=".json_encode($jsonData).";";
file_put_contents("test.json",$json_string);
?
?php
class FileAction extends Action {
public function Index()
{
//print_r(__URL__);
$file = M('file');
$list = $file-select();
$this-assign('filelist',$list);
$this-display();
}
public function upload()
{
//文件上傳的地址上傳給它,并且上傳完成后返回一個信息,讓其寫入數(shù)據(jù)庫
//如果$_FILES為空的畫,我就讓action給出一個錯誤提示,告訴用戶必須選擇上傳文件。如果有上傳文件,則調(diào)用up方法
//$_FILES = $this-_post('file');
//print_r($_FILES);
if (empty($_FILES)) {
$this-error('必須選擇上傳文件');
}else {
$a = $this-Up();
//print_r($a);
if (isset($a)) {
//寫入數(shù)據(jù)庫方法
if($this-c($a)) {
$this-success('上傳成功');
}else {
$this-error('寫入數(shù)據(jù)庫失敗');
}
}else {
$this-error('上傳文件有異常請與系統(tǒng)管理員聯(lián)系');
}
}
}
private function c($data)
{
//print_r($data);
$file=M('file');
$num = '0';
for($i = 0; $i count($data)-1; $i++) {
$data['filename']=$data[$i]['savename'];
if( $file-data($data)-add())
{
$num++;
}
}
if($num==count($data)-1)
{
return true;
}else {
return false;
}
}
// private function c($data)
// {
// $file = M('file');
// $data['filename'] = $data[0]['savename'];
// if ($file-data($data)-add()) {
// return true;
// }else {
// return false;
// }
// }
//在這個方法當中,完成與thinkphp相關的,文件上傳類的調(diào)用
private function Up()
{
//echo '模擬上傳';
//基本上傳功能
//批量上傳功能
//生成圖片縮略圖
//自定義參數(shù)上傳
//上傳檢測(大小,后綴,mime類型)
//支持覆蓋方式上傳
//上傳類型,附件大小,上傳路徑定義
//支持hash或者日期子目錄保存上傳文件
//上傳圖片的安全性檢測
//對上傳文件的hash檢測
//上傳文件名自定義規(guī)范
import('@.ORG.UploadFile');
import('@.ORG.Image');
$upload = new UploadFile();
$upload-maxSize = '1000000'; //指上傳文件大小,默認為-1,不限制大?。╞ytes)
$upload-savePath = './Public/'; //上傳保存到什么地方?路徑建議保存到入口文件平級或平級目錄的子目錄
$upload-saveRule = 'uniqid'; //上傳文件的文件名保存規(guī)則 time uniqid(默認) com_create_guid
$upload-hashType = 'md5_file';
$upload-autoCheck = true; //是否自動檢測附件 默認true
$upload-uploadReplace = true; //如果存在同名文件是否進行覆蓋
$upload-allowExts = array('jpg','jpeg','png','gif'); //允許上傳的文件后綴
$upload-allowPath = array('image/png','image/jpg','image/pjpeg','image/gif','image/jpeg'); //檢測mime類型
$upload-thumb = true; // 是否開啟圖片文件縮略
$upload-thumbMaxWidth = '300,500';//縮略圖最大寬度
$upload-thumbMaxHeight = '200,400';//最大高度
$upload-thumbPrefix = 's-,m-';//縮略圖文件前綴
//$upload-thumbSuffix = '_s,_m';//文件后綴
//$upload-thumbPath = '';//如果留空直接上傳至
//$upload-thumbFile 在數(shù)據(jù)庫中也存一個文件名即可
$upload-thumbRemoveOrigin = 1; //如果生成縮略圖,是否刪除原圖
//$upload-autoSub 是否使用子目錄進行保存上傳文件
//$upload-subType='' 子目錄創(chuàng)建方式默認為hash 也可以為date
//$upload-dateFormat 子目錄方式date的指定日期格式
//$upload-hashLevle
//upload() 如果上傳成功返回true,失敗返回false
if ($upload-upload()) {
$info = $upload-getUploadFileInfo();
return $info;
}else {
//是專門來獲取上傳的錯誤信息的
$this-error($upload-getErrorMsg());
}
}
}
?
插一條數(shù)據(jù),也要把內(nèi)容作為字符串讀入內(nèi)存,修改后再寫回文件。
首先創(chuàng)建 一個HTML頁面userinfo_add.php,在里面輸入表單,文本框,輸入需要提交的到數(shù)據(jù)庫的信息:
賬號 姓名 年齡
頁面運行結果:
創(chuàng)建一個PHP文件(userinfo_insert.php),用來處理頁面請求的,就是具體往數(shù)據(jù)庫添加數(shù)據(jù)的代碼:
先獲取頁面數(shù)據(jù)
//通過post獲取頁面提交數(shù)據(jù)信息 $userId = $_POST[userId];
$userName = $_POST[userName];
$userAge = $_POST[userAge];
接下來,在連接數(shù)據(jù)庫 ‘test’
//地址
$url = "127.0.0.1";
//賬號
$user = "root";
//密碼
$password = "root";
//連接
$con = mysql_connect($url,$user,$password);
//設置編碼機
mysql_query("set names 'utf8'");
//連接數(shù)據(jù)庫
mysql_select_db("test");
編寫SQL,執(zhí)行SQL添加數(shù)據(jù)
$sql = "insert into user_info (user_id,user_name,user_age) values('$userId','$userName','$userAge')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "添加一條記錄";
//關閉連接
mysql_close($con)
運行結果前:
運行結果后:
完整代碼:
/*先取出*/
$string = file_get_contents("1.txt");
$newstring; // 新數(shù)據(jù)
if (empty($string)) {
$string = $newstring;
} else {
$string .= '|' . $newstring;
}
file_put_contents("1.txt", $string);