#!/bin/bash
ip=$1
phone_no_before=$2
phone_no_after=$3
name=$4
id_no=$5
port=$6
DBNAME="payment_center"
TABLENAME="user_detail"
TABLENAME1="user"
mysqld="-h$ip -P$port -uqa -pqatest"

function updatecarddetail()
{
	len=`echo $phone_no_before|awk '{print length($0)}'`
        if [ $len -ne 11 ]
        	then
                echo "请输入11位手机号!"     
        else
        	echo "开始修改"
			#查询userID
			select_sql="select id from ${TABLENAME1} where phone_no=${phone_no_before}"
			#echo "$select_sql"
			user_id=`mysql -N $mysqld ${DBNAME} -e "${select_sql}"`
			echo "user_id=$user_id"

			#插入授信数据0和3
			update_sql="update ${TABLENAME} set phone_no=$phone_no_after,name='$name',id_no=$id_no where user_id=${user_id}"

			#echo "$update_sql"
			#echo "$insert_sql3"
			mysql $mysqld ${DBNAME} -e "${update_sql}"	
			echo "修改成功"
            break
        fi

}

updatecarddetail $ip $phone_no_before $phone_no_after $name $id_no