English 中文(简体)
PHP 进口
原标题:PHP Class Import
  • 时间:2011-10-28 13:10:48
  •  标签:
  • php

在此,我试图从另一个网页上打一个样本代码,帮助我获得雕像。 我看不出工作。 我如何进口这一类产品,并将这一类别列入另一个存放地点档案? <代码>stats.php

<?php

include("config.php");
$link = mysql_connect($host, $username, $password);
mysql_select_db("mydb", $link);

class stats{

  function newReg(){

    $result = mysql_query("SELECT * FROM people where status = registered  ", $link);
    $num_rows = mysql_num_rows($result);
     return $num_rows ;


function newApp(){
    $result = mysql_query("SELECT * FROM people where status =  NEW  ", $link);
    $num_rows = mysql_num_rows($result);

    return $num_rows;
 }
?>

我想在另一个档案中把这一类人称为:

<?php

require_once("stats.php");
   echo(stats.newReg());

 ?>

Is there something I m missing here?

最佳回答

you forgot 2 closing brackets

<?php

include("config.php");
$link = mysql_connect($host, $username, $password);
mysql_select_db("mydb", $link);

class stats{

  function newReg(){
    global $link;
    $result = mysql_query("SELECT * FROM people where status = registered  ", $link);
    $num_rows = mysql_num_rows($result);
     return $num_rows ;
  }

function newApp(){
    global $link;        
    $result = mysql_query("SELECT * FROM people where status =  NEW  ", $link);
    $num_rows = mysql_num_rows($result);

    return $num_rows;
 }
}
?>

任何其他档案:

include  statsclassfile.php ;
$myStats = new stats();
$mystats->newReg();

PS:命名公约一般都要求从资本信件开始,例如:<代码>Stats。

问题回答

确保道路是正确的,或许是会合。 php的档案不是同一个文件。

你们可以采取像这样的绝对道路。

require_once $_SERVER[ DOCUMENT_ROOT ] . "/path_to_config/config.php";

并称职:

require_once PATH_TO_YOUR_CLASS . "stats.php"

还确保你以CamelCased的名字命名班。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签