如何在php oops中编写常用的select函数 [英] how to write a common select function in php oops

查看:70
本文介绍了如何在php oops中编写常用的select函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

define('DB_SERVER','localhost');

define('DB_USER','root');

define('DB_PASS','') ;

define('DB_NAME','product_db');



connect.php

class DB_con < br $>
{

函数__construct()

{

$ conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS)或死('localhost connection problem'.mysql_error());

mysql_select_db(DB_NAME,$ conn);

}



公共函数select()

{

$ res = mysql_query(SELECT products.product_id,customer.name,products.product_name,customer.address,delivery。 order_date FROM customer,products,delivery where delivery.order_date<'2015-03-05'AND delivery.product_id = products.product_id group by products.product_id);

return $ res;

}

}



?>

restaurent.php

<!DOCTYPE html>

< ht ml xmlns =http://www.w3.org/1999/xhtml>

< head>

< / head>



< body>





include_once'dbconnect.php';

$ con = new DB_con();



$ res = $ con> select();







while($ row = mysql_fetch_array($ res))

{

?>




















}

?>

< TD>餐饮
cusin_id cusine_name category


< / body>

< / html>

define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'product_db');

connect.php
class DB_con
{
function __construct()
{
$conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysql_select_db(DB_NAME, $conn);
}

public function select()
{
$res=mysql_query("SELECT products.product_id, customer.name, products.product_name, customer.address, delivery.order_date FROM customer,products,delivery where delivery.order_date < '2015-03-05' AND delivery.product_id = products.product_id group by products.product_id ");
return $res;
}
}

?>
restaurent.php
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>

<body>


include_once 'dbconnect.php';
$con = new DB_con();

$res=$con->select();



while($row=mysql_fetch_array($res))
{
?>










}
?>

cusin_id cusine_name category restaurent amount total

</body>
</html>

推荐答案

conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS)或者死('localhost connection problem'.mysql_error());

mysql_select_db(DB_NAME,
conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysql_select_db(DB_NAME,


conn);

} < br $>


公共函数select()

{
conn);
}

public function select()
{


res = mysql_query(SELECT products.product_id,customer.name,products.product_name,customer.address,delivery.order_date FROM customer,products,delivery where delivery.order_date< '2015-03-05'AND delivery.product_id = products.product_id group by products.product_id);

return
res=mysql_query("SELECT products.product_id, customer.name, products.product_name, customer.address, delivery.order_date FROM customer,products,delivery where delivery.order_date < '2015-03-05' AND delivery.product_id = products.product_id group by products.product_id ");
return


这篇关于如何在php oops中编写常用的select函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆