本文目录一览:
php mysql 增删改查 源代码
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
高分 求php 批量写入mysql表,简化源代码。不要复制粘贴别人的。
1、批量生成注册码的示例代码如下:
?php
$Codes = GenCode(100);
echo 'pre';
print_r($Codes);
echo '/pre';
function GenCode($GenCount)
{
$CodeArr = array();
$KeyStr = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for ($d = 1; $d = $GenCount; $d++) {
$CodeStr = '';
for ($i = 1; $i 5; $i++) {
$Keys = str_shuffle($KeyStr);
$CodeStr = $CodeStr . '-' . substr($Keys,1,4);
}
$CodeArr[] = substr($CodeStr,1);
}
array_unique($Codes);
return $CodeArr;
}
代码运行截图:
2、将上面的数据保存到 txt 文件,代码示例:
?php
$Codes = GenCode(100);
SaveToTxt('./test.txt',$Codes);
function SaveToTxt($FileName, $CodeArray)
{
$fp = fopen($FileName, "w+") or die("打开 $FileName 失败。");
fwrite($fp, implode("rn", $CodeArray)) or die("写入 $FileName 数据失败。");
fclose($fp);
}
高分 php mysql 源码修改 请将 完整代码 作为答案就行了
?php
function fetch_password($host , $db_user , $db_pwd , $db , $db_table='user' , $account=''){
$sql = "select password from ${db_table} where account='${account}';";
$ary_pwd = array();
if($conn = mysql_connect($host , $db_user , $db_pwd)){
if(mysql_select_db($db)){
if($result = mysql_query($sql)){
if(mysql_affected_rows()){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push($ary_pwd, $row['password']);
}
}
mysql_free_result($result);
}else{
die('Error : ' . mysql_error());
}
}else{
die('Could not select db: ' . mysql_error());
}
mysql_close($conn);
}else{
die('Could not connect: ' . mysql_error());
}
return $ary_pwd;
}
$host = '127.0.0.1';
$db_user = 'root';
$db_pwd = '123456';
$db = 'test';
$db_table= 'user';
$account = mysql_real_escape_string($_GET['account']);
$rlt = fetch_password($host , $db_user , $db_pwd , $db , $db_table , $account);
echo join($rlt ,PHP_EOL);