warning mysql_query,警告:mysql_query()期望参数2为资源

what's the problem in my code ?

this is full of my connection code...

please help me what's the wrong in this code ?

define("Server", "localhost");//constant for connennection

define("Username", "root");

define("Password", "123456");

?>

$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());

}

?>

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;

}

}

?>

I try to run this but every time has error what should I do. I couldn't find my mistake.

解决方案

It seems that you have not initialized your connection.

You should add

mysql_connect($host, $username, $password);

and only after that do

mysql_query($query);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值