phpmysql源代碼
本地先需要架設PHP+MYSQL的伺服器,然後根據提示安裝代碼。
一般有倆種安裝方式
一種非常簡單,直接把代碼復制到PHP+MYSQL的伺服器的根目錄。按照提示訪問,一直確定就行
一種相對復雜點,把代碼復制到PHP+MYSQL的伺服器的根目錄。然後根據提示找到資料庫連接文件,用網頁編程工具把資料庫改成你的,這個先要在MYSQL中建立資料庫,再找到你的代碼的數據備份導入資料庫就行。
要想復雜就很復雜,建議先學習各類網頁工具和資料庫工具。
2. 高分 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);
3. 完整的php&mysql的留言板源代碼,可以運行的
input.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="receive.php">
<p>您的姓名: <input type="text" name="T1" size="20"></p>
<p>您的性別:男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1"></p>
<p>您的EMAIL:<input type="text" name="T2" size="35"></p>
<p>您的留言內容:</p>
<p> <textarea rows="16" name="S1" cols="45"></textarea></p>
<p> </p>
<p> <input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
receive.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$sql = "INSERT INTO `guestbook`.`gbook` (`id`, `name`, `sex`, `email`, `info`, `ip`, `time_at`) VALUES (NULL, '$T1', '$R1', '$T2', '$S1', '$ip', NOW());";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
mysql_query($sql);
$result=mysql_query("select * from $table");
while ($arr=mysql_fetch_array($result))
{
if ($arr[2]==0)
$gender='先生';
else
$gender='女士';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Receive</title>
</head>
<body style="background-attachment: fixed">
<table border="1" width="100%" id="table1" bgcolor="#FFFFFF">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#C0C0C0"><?=$arr[6]?>(<?=$arr[5]?>)<p><?=$arr[1]?> <?=$gender?><<a href="<?=$arr[3]?>"><?=$arr[3]?></a>>
寫到:</td>
</tr>
<tr>
<td><?=$arr[4]?><p> </p>
<p><a href="del.php?id=<?=$arr[0]?>">[刪除]</a>
<a href="modify.php?id=<?=$arr[0]?>">[修改]</a>]</td>
</tr>
</table>
</body>
</html>
<?php
echo '<p>';
echo '<p>';
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="input.htm"><繼續留言></a></p>
</body>
</html>
del.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$sql="DELETE FROM $table WHERE id=$id";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query($sql);
if ($result)
echo "刪除成功";
else
echo "刪除失敗";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="receive.php"><返回首頁></a></p>
</body>
</html>
modify.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query("select * from $table where id=$id");
$arr=mysql_fetch_array($result);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="modify_ok.php?id=<?=$id?>">
<p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[1]?>"></p>
<p>您的性別:
<?php
if ($arr[2]==0) echo '男<input type="radio" value="0" name="R1" checked>
女<input type="radio" name="R1" value="1"></p>';
else echo '男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1" checked></p>';
?>
<p>您的EMAIL:<input type="text" name="T2" size="35" value="<?=$arr[3]?>"></p>
<p>您的留言內容:</p>
<p> <textarea rows="16" name="S1" cols="45" ><?=$arr[4]?></textarea></p>
<p> </p>
<p> <input type="submit" value="修改" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
modify_ok.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);;
$sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;";
$result=mysql_query($sql);
if ($result)
echo "修改成功";
else
echo "修改失敗";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="input.htm"><繼續留言></a></p>
</body>
</html>
4. PHP+mysql網站源碼如何安裝
這個是在伺服器端安裝php,並且關聯mysql的一個步驟和提示。
具體步驟如下(以phpcms為例):
1. 安裝網站程序
在新的網站輸入http://您的域名/install/ 安裝與原來網站字元一致的PHPCMS V9,在資料庫是需要用到資料庫名和頭,請使用上面一些的內容,如sooks與dns。資料庫配置文件在「caches/configs」文件夾下的「database.php」,這里主要是資料庫的名稱及頭。(只要修改好配置文件一致就行)
2. 上傳原網站備份數據
將備份的SQL文件上傳到新的網站"caches/bakup"文件夾。
3. 上傳原網站模板
將原來網站的模板文件上傳到"phpcms/templates"文件夾。
4. 上傳CSS文件
如果沒有使用默認程序的CSS,請將備份的CSS上傳到「statics/css」
5. 上傳附件
將下載的「uploadfile」文件夾上傳到新的網站根目錄下。
6. 恢復數據
登錄到新網站的後台,在「擴展」菜單下的「資料庫工具」中選擇「數據導入」,在下面選擇上傳的備份數據,請檢查是否完整,選中全部後單擊「恢復」將數據進行恢復。 站點管理域名
7. 更新網站緩沖
完成數據恢復後,請更新全站的緩沖,再檢查相應的欄目數據是否完成。
8. 生成網站與欄目及首頁
檢查網站的設置後,生成網站的網頁、欄目及首頁,就可以完成了。
5. 如何使用php登錄mysql,使用mysqli的登錄方式,並插入一條數據,誰有有完整的php原代碼
本文所述的是一個在PHP中以mysqli方式連接資料庫的一個資料庫類實例,該資料庫類是從一個PHP的CMS中整理出來的,可實現PHP連接資料庫類,MySQLi版,兼容PHP4,對於有針對性需要的朋友可根據此代碼進行優化和修改。
?
<?php
#==================================================================================================
# Filename: /db/db_mysqli.php
# Note : 連接資料庫類,MySQLi版
#==================================================================================================
#[類庫sql]
class db_mysqli
{
var $query_count = 0;
var $host;
var $user;
var $pass;
var $data;
var $conn;
var $result;
var $prefix = "qinggan_";
//返回結果集類型,默認是數字+字元
var $rs_type = MYSQLI_ASSOC;
var $query_times = 0;#[查詢時間]
var $conn_times = 0;#[連接資料庫時間]
var $unbuffered = false;
//定義查詢列表
var $querylist;
var $debug = false;
#[構造函數]
function __construct($config=array())
{
$this->host = $config['host'] ? $config['host'] : 'localhost';
$this->port = $config['port'] ? $config['port'] : '3306';
$this->user = $config['user'] ? $config['user'] : 'root';
$this->pass = $config['pass'] ? $config['pass'] : '';
$this->data = $config['data'] ? $config['data'] : '';
$this->debug = $config["debug"] ? $config["debug"] : false;
$this->prefix = $config['prefix'] ? $config['prefix'] : 'qinggan_';
if($this->data)
{
$ifconnect = $this->connect($this->data);
if(!$ifconnect)
{
$this->conn = false;
return false;
}
}
return true;
}
#[兼容PHP4]
function db_mysqli($config=array())
{
return $this->__construct($config);
}
#[連接資料庫]
function connect($database="")
{
$start_time = $this->time_used();
if(!$this->port) $this->port = "3306";
$this->conn = @mysqli_connect($this->host,$this->user,$this->pass,"",$this->port) or false;
if(!$this->conn)
{
return false;
}
$version = $this->get_version();
if($version>"4.1")
{
mysqli_query($this->conn,"SET NAMES 'utf8'");
if($version>"5.0.1")
{
mysqli_query($this->conn,"SET sql_mode=''");
}
}
$end_time = $this->time_used();
$this->conn_times += round($end_time - $start_time,5);#[連接資料庫的時間]
$ifok = $this->select_db($database);
return $ifok ? true : false;
}
function select_db($data="")
{
$database = $data ? $data : $this->data;
if(!$database)
{
return false;
}
$this->data = $database;
$start_time = $this->time_used();
$ifok = mysqli_select_db($this->conn,$database);
if(!$ifok)
{
return false;
}
$end_time = $this->time_used();
$this->conn_times += round($end_time - $start_time,5);#[連接資料庫的時間]
return true;
}
#[關閉資料庫連接,當您使用持續連接時該功能失效]
function close()
{
if(is_resource($this->conn))
{
return mysqli_close($this->conn);
}
else
{
return true;
}
}
function __destruct()
{
return $this->close();
}
function set($name,$value)
{
if($name == "rs_type")
{
$value = strtolower($value) == "num" ? MYSQLI_NUM : MYSQLI_ASSOC;
}
$this->$name = $value;
}
function query($sql)
{
if(!is_resource($this->conn))
{
$this->connect();
}
else
{
if(!mysql_ping($this->conn))
{
$this->close();
$this->connect();
}
}
if($this->debug)
{
$sqlkey = md5($sql);
if($this->querylist)
{
$qlist = array_keys($this->querylist);
if(in_array($sqlkey,$qlist))
{
$count = $this->querylist[$sqlkey]["count"] + 1;
$this->querylist[$sqlkey] = array("sql"=>$sql,"count"=>$count);
}else{
$this->querylist[$sqlkey] = array("sql"=>$sql,"count"=>1);
}
}
else{
$this->querylist[$sqlkey] = array("sql"=>$sql,"count"=>1);
}
}
$start_time = $this->time_used();
$func = $this->unbuffered && function_exists("mysqli_multi_query") ? "mysqli_multi_query" : "mysqli_query";
$this->result = @$func($this->conn,$sql);
$this->query_count++;
$end_time = $this->time_used();
$this->query_times += round($end_time - $start_time,5);#[查詢時間]
if(!$this->result)
{
return false;
}
return $this->result;
}
function get_all($sql="",$primary="")
{
$result = $sql ? $this->query($sql) : $this->result;
if(!$result)
{
return false;
}
$start_time = $this->time_used();
$rs = array();
$is_rs = false;
while($rows = mysqli_fetch_array($result,$this->rs_type))
{
if($primary && $rows[$primary])
{
$rs[$rows[$primary]] = $rows;
}
else
{
$rs[] = $rows;
}
$is_rs = true;
}
$end_time = $this->time_used();
$this->query_times += round($end_time - $start_time,5);#[查詢時間]
return ($is_rs ? $rs : false);
}
function get_one($sql="")
{
$start_time = $this->time_used();
$result = $sql ? $this->query($sql) : $this->result;
if(!$result)
{
return false;
}
$rows = mysqli_fetch_array($result,$this->rs_type);
$end_time = $this->time_used();
$this->query_times += round($end_time - $start_time,5);#[查詢時間]
return $rows;
}
function insert_id($sql="")
{
if($sql)
{
$rs = $this->get_one($sql);
return $rs;
}
else
{
return mysqli_insert_id($this->conn);
}
}
function insert($sql)
{
$this->result = $this->query($sql);
$id = $this->insert_id();
return $id;
}
function all_array($table,$condition="",$orderby="")
{
if(!$table)
{
return false;
}
$table = $this->prefix.$table;
$sql = "SELECT * FROM ".$table;
if($condition && is_array($condition) && count($condition)>0)
{
$sql_fields = array();
foreach($condition AS $key=>$value)
{
$sql_fields[] = "`".$key."`='".$value."' ";
}
$sql .= " WHERE ".implode(" AND ",$sql_fields);
}
if($orderby)
{
$sql .= " ORDER BY ".$orderby;
}
$rslist = $this->get_all($sql);
return $rslist;
}
function one_array($table,$condition="")
{
if(!$table)
{
return false;
}
$table = $this->prefix.$table;
$sql = "SELECT * FROM ".$table;
if($condition && is_array($condition) && count($condition)>0)
{
$sql_fields = array();
foreach($condition AS $key=>$value)
{
$sql_fields[] = "`".$key."`='".$value."' ";
}
$sql .= " WHERE ".implode(" AND ",$sql_fields);
}
$rslist = $this->get_one($sql);
return $rslist;
}
//將數組寫入數據中
function insert_array($data,$table,$insert_type="insert")
{
if(!$table || !is_array($data) || !$data)
{
return false;
}
$table = $this->prefix.$table;//自動增加表前綴
if($insert_type == "insert")
{
$sql = "INSERT INTO ".$table;
}
else
{
$sql = "REPLACE INTO ".$table;
}
$sql_fields = array();
$sql_val = array();
foreach($data AS $key=>$value)
{
$sql_fields[] = "`".$key."`";
$sql_val[] = "'".$value."'";
}
$sql.= "(".(implode(",",$sql_fields)).") VALUES(".(implode(",",$sql_val)).")";
return $this->insert($sql);
}
//更新數據
function update_array($data,$table,$condition)
{
if(!$data || !$table || !$condition || !is_array($data) || !is_array($condition))
{
return false;
}
$table = $this->prefix.$table;//自動增加表前綴
$sql = "UPDATE ".$table." SET ";
$sql_fields = array();
foreach($data AS $key=>$value)
{
$sql_fields[] = "`".$key."`='".$value."'";
}
$sql.= implode(",",$sql_fields);
$sql_fields = array();
foreach($condition AS $key=>$value)
{
$sql_fields[] = "`".$key."`='".$value."' ";
}
$sql .= " WHERE ".implode(" AND ",$sql_fields);
return $this->query($sql);
}
function count($sql="")
{
if($sql)
{
$this->rs_type = MYSQLI_NUM;
$this->query($sql);
$rs = $this->get_one();
$this->rs_type = MYSQLI_ASSOC;
return $rs[0];
}
else
{
return mysqli_num_rows($this->result);
}
}
function num_fields($sql="")
{
if($sql)
{
$this->query($sql);
}
return mysqli_num_fields($this->result);
}
function list_fields($table)
{
$rs = $this->get_all("SHOW COLUMNS FROM ".$table);
if(!$rs)
{
return false;
}
foreach($rs AS $key=>$value)
{
$rslist[] = $value["Field"];
}
return $rslist;
}
#[顯示表名]
function list_tables()
{
$rs = $this->get_all("SHOW TABLES");
return $rs;
}
function table_name($table_list,$i)
{
return $table_list[$i];
}
function escape_string($char)
{
if(!$char)
{
return false;
}
return mysqli_escape_string($this->conn,$char);
}
function get_version()
{
return mysqli_get_server_info($this->conn);
}
function time_used()
{
$time = explode(" ",microtime());
$used_time = $time[0] + $time[1];
return $used_time;
}
//Mysql的查詢時間
function conn_times()
{
return $this->conn_times + $this->query_times;
}
//MySQL查詢資料
function conn_count()
{
return $this->query_count;
}
# 高效SQL生成查詢,僅適合單表查詢
function phpok_one($tbl,$condition="",$fields="*")
{
$sql = "SELECT ".$fields." FROM ".$this->db->prefix.$tbl;
if($condition)
{
$sql .= " WHERE ".$condition;
}
return $this->get_one($sql);
}
function debug()
{
if(!$this->querylist || !is_array($this->querylist) || count($this->querylist) < 1)
{
return false;
}
$html = '<table cellpadding="0" cellspacing="0" width="100%" bgcolor="#CECECE"><tr><td>';
$html.= '<table cellpadding="1" cellspacing="1" width="100%">';
$html.= '<tr><th bgcolor="#EFEFEF" height="30px">SQL</th><th bgcolor="#EFEFEF" width="80px">查詢</th></tr>';
foreach($this->querylist AS $key=>$value)
{
$html .= '<tr><td bgcolor="#FFFFFF"><div style="padding:3px;color:#6E6E6E;">'.$value['sql'].'</div></td>';
$html .= '<td align="center" bgcolor="#FFFFFF"><div style="padding:3px;color:#000000;">'.$value["count"].'</div></td></tr>';
}
$html.= "</table>";
$html.= "</td></tr></table>";
return $html;
}
function conn_status()
{
if(!$this->conn) return false;
return true;
}
}
?>
6. 高分 求php 批量寫入mysql表,簡化源代碼。不要復制粘貼別人的。
1、批量生成注冊碼的示例代碼如下:
<?php
$Codes=GenCode(100);
echo'<pre>';
print_r($Codes);
echo'</pre>';
functionGenCode($GenCount)
{
$CodeArr=array();
$KeyStr='';
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;
}
代碼運行截圖:
<?php
$Codes=GenCode(100);
SaveToTxt('./test.txt',$Codes);
functionSaveToTxt($FileName,$CodeArray)
{
$fp=fopen($FileName,"w+")ordie("打開$FileName失敗。");
fwrite($fp,implode("
",$CodeArray))ordie("寫入$FileName數據失敗。");
fclose($fp);
}
7. PHP 從Excel導入到MySQL 源代碼錯誤指導
$dati->read('$indirizzo');//這是第一個錯誤,雖然不會報錯,但你不能加單引號。
$dati->sheets[1][1][2]//這種寫法是錯誤的親。如果要獲取數組值,請賦值後再用健值隊。
8. 求PHP和MySQL部門考核系統源代碼,最好是基於WEB的
在線模擬考試系統基於PHP+Mysql開發,主要用於搭建模擬考試平台,支持多種題型和展現方式,是國內首款支持題冒題和自動評分與教師評分相結合的PHP開源在線模擬考試系統。使用本系統,您可以快速搭建用於模擬考試的網站平台,實現無紙化考試、真實考場模擬、知識強化練習等功能。可滿足培訓機構、學校、公司等機構各種考試需求。
9. PHP mysql源碼怎麼在本地連接資料庫啊
欄中,打 把你的資料庫導進去就好了呀,再把你要測試的網站源碼放在www文件夾下,然後在文件名/index.php打開就行了,還有你要看你源碼中資料庫的配置,要改成你本地的,如果是在線安裝的就不要改。
10. mysql資料庫怎麼鏈接到php源碼上
第一,買個PHP的空間,要帶送MYsql資料庫的(比如老品牌主機laopinpai.net),然後開通空間後,就會得到贈送的資料庫。
第二 把源碼上傳到網站空間上,按源碼要求操作。如果是需要安裝的,就直接安裝程序,然後填寫提示要填寫的資料庫的信息,比如IP 用戶名密碼。就行了。
第三,如果是有資料庫需要恢復的,把數據傳到空間讓,聯系空間商幫你恢復一下數據到你的資料庫就搞定了。