先mysql_connect()到mysql再做mysql_query()的相關(guān)操作。
新市網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),新市網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為新市成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的新市做網(wǎng)站的公司定做!
====================================================================
?php
$server = "localhost";
$username = "root";
$password = "";
$database = "myabc";
$ranks = array(
1="newbie",
2="new member",
3="member",
4="high member",
5="very high member",
6="supreme member",
7="ultra member",
8="godlike member",
9="god member",
10="low god",
11="medium god",
12="high god",
13="very high god",
14="supreme god",
15="ultra god",
16="perfect"
);
$couldNotOpenDatabase = "Could not open databaseBR\n please check your settings in config.php";
$couldNotConnectMysql="Could not connect Mysql!";
$conn=mysql_connect($server,$username,$password) or die ($couldNotConnectMysql);
if (mysql_select_db($database,$conn))
{//數(shù)據(jù)庫(kù)存在,做相應(yīng)操作
}
else
{//數(shù)據(jù)庫(kù)不存在,創(chuàng)建一個(gè),并做相應(yīng)操作
$query = "CREATE DATABASE $database";
$result = mysql_query($query);
mysql_select_db($database,$conn)or die ($couldNotOpenDatabase);
}
?
PHP連接數(shù)據(jù)庫(kù)之PHP連接MYSQL數(shù)據(jù)庫(kù)代碼
?php???
$mysql_server_name='localhost';?
//改成自己的mysql數(shù)據(jù)庫(kù)服務(wù)器??
$mysql_username='root';?
//改成自己的mysql數(shù)據(jù)庫(kù)用戶名??
$mysql_password='12345678';?
//改成自己的mysql數(shù)據(jù)庫(kù)密碼??
$mysql_database='mycounter';
//改成自己的mysql數(shù)據(jù)庫(kù)名??
$conn=mysql_connect($mysql_server_name,
$mysql_username,$mysql_password,
$mysql_database);???
$sql='CREATE?DATABASE?mycounter?
DEFAULT?CHARACTER?SET?gbk?COLLATE?gbk_chinese_ci;???
';???
mysql_query($sql);???
$sql='CREATE?TABLE?`counter`?
(`id`?INT(255)?UNSIGNED?NOT?NULL?
AUTO_INCREMENT?,`count`?INT(255)?
UNSIGNED?NOT?NULL?DEFAULT?0,PRIMARY?KEY?
(?`id`?)?)?TYPE?=?innodb;';???
mysql_select_db($mysql_database,$conn);???
$result=mysql_query($sql);???
//echo?$sql;???
mysql_close($conn);???
echo?"Hello!數(shù)據(jù)庫(kù)mycounter已經(jīng)成功建立!";???
??
PHP連接數(shù)據(jù)庫(kù)之PHP連接ACCESS數(shù)據(jù)庫(kù)代碼方法
???
$conn?=?new?com("ADODB.Connection");???
$connstr?=?"DRIVER={Microsoft
Access?Driver?(*.mdb)};?
DBQ=".?realpath("data/db.mdb");???
$conn-Open($connstr);???
$rs?=?new?com("ADODB.RecordSet");???
$rs-Open("select?*
from?szd_t",$conn,1,1);???
while(!?$rs-eof)?{???
$f?=?$rs-Fields(1);???
echo?$f-value;???
$rs-MoveNext();???
}???
?
數(shù)據(jù)庫(kù)的設(shè)計(jì)本人認(rèn)為可以這樣,提交表單應(yīng)該再設(shè)置一個(gè)隱藏域,儲(chǔ)存題目ID,例如
" name="an_id"
處理頁(yè)面可以使用將獲取到的答案數(shù)組
$_POST['itm']進(jìn)行遍歷,用循環(huán)$value查找question,可以使用函數(shù)strpos(),該函數(shù)如果返回?cái)?shù)字,則是正確答案,如果返回false,則是錯(cuò)誤答案
if(isset($_POST['an_id'])){
$an_id = $_POST['an_id'];
$qus_sql = "select `question` from `vote_answer` where id = $an_id";
$query = mysql_query($qus_sql);
while($row = mysql_fetch_row($query)){
$question = $row[0];
}
$user_question = $_POST['itm'];
foreach($user_question as $value){
if(strpos($question,$value){
echo '正確答案';
}else{
echo '錯(cuò)誤答案';
}
}
}全手寫代碼,有錯(cuò)誤請(qǐng)百度HI我!