我的代碼中有什麼問題?
這是完整的我的連接代碼...
請幫我在這段代碼中有什麼錯?
警告:mysql_query()期望參數2是資源
<?php
define("Server", "localhost");//constant for connennection
define("Username", "root");
define("Password", "123456");
?>
<?php // connection
$conection= mysql_connect(Server, Username, Password);
if(!$conection)
die("connection faild :". mysql_error());
$db_select= mysql_select_db("widget",$conection);
if (!$db_select) {
die("selection faild :".mysql_error());
}
?>
<?php
function conform_query($result){
if (!$result) {
die("query failed :".mysql_error()); }
}
function get_subject_by_id($subject_id) {
global $conection;
$query = "SELECT * ";//data base query
$query .= "FROM subject ";
$query .= "WHERE id= " . $subject_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $conection);
conform_query($result_set);
// REMEMBER:
// if no rows are returned, fetch_array will return false
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
}
else {
return NULL;
}
}
?>
我嘗試運行這一點,但每次有錯誤怎麼辦。我找不到我的錯誤。
哪裏是你的數據庫連接配置?請用它更新你的答案。 – ManinGreen