php中包含函数的级别是什么?
我正在使用include函数。我想知道它的使用水平。说到这里,我有一个名为hitcounter.php的页面,我想知道在我的应用程序中该页面被点击了多少次。所以我创建了hitcounter.phpphp中包含函数的级别是什么?,php,Php,我正在使用include函数。我想知道它的使用水平。说到这里,我有一个名为hitcounter.php的页面,我想知道在我的应用程序中该页面被点击了多少次。所以我创建了hitcounter.php <?php include"../includes/subpageheader.php"; include"../includes/hitcounter.php"; ?> 我的问题是我在我的一个页面中包含了这个hitcounter.php,我想知道这个特定的点击率并将其存储
<?php include"../includes/subpageheader.php";
include"../includes/hitcounter.php";
?>
我的问题是我在我的一个页面中包含了这个hitcounter.php,我想知道这个特定的点击率并将其存储在db中。在hitcounter.php中,我包含了dbconnection.php。当我登录到我的应用程序时,我点击了包含hitcounter.php的特定页面,它给出了一个错误:未选择任何数据库
在我2.8年的工作经验中,我第一次在谷歌上搜索到了这个错误,但我没有找到答案
我的密码:
include"dbconnection.php";
//Adds one to the counter
mysql_query("UPDATE counter SET patient_dashboard = patient_dashboard + 1")or die (mysql_error());
//Retreives the current count
$count = mysql_fetch_row(mysql_query("SELECT patient_dashboard FROM counter"))or die(mysql_error());
//Displays the count on your site
print "$count[0]";
这就是我如何包含hit counter.php的方法
<?php include"../includes/subpageheader.php";
include"../includes/hitcounter.php";
?>
mydatabase连接代码:
$conn=mysql_connect('localhost','root','');
//echo $conn."<br/>";
$db=mysql_select_db('health');
$conn=mysql\u connect('localhost','root','');
//echo$conn.“
”;
$db=mysql_select_db('health');
我想知道我们在php中使用了多少级别的include函数。因此,如何解决此错误请任何人帮助我。在我看来,您的错误与包含无关,问题是您没有选择数据库,请看以下示例:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>
包括
关于的解释包括找到的php文档中的
根据给定的文件路径包含文件,如果未给定,则根据指定的包含路径包含文件。如果在include_路径中找不到该文件,include将在失败之前最终签入调用脚本自己的目录和当前工作目录。如果include构造找不到文件,它将发出警告;这与require不同,require将发出致命错误
您可以通过使用带有函数和函数的根目录
清理include,然后创建文件的路径。例如
<?php
$my_root = $_SERVER['DOCUMENT_ROOT'];
$subpageheaderphp = $my_root . "/direct/path/to/file/from/root/subpageheader.php";
if(file_exists($subpageheaderphp)){include $subpageheaderphp;}else{echo "subpageheader in directory $subpageheaderphp could not be found <br/>";}
$hitcounterphp = $my_root . "/direct/path/to/file/from/root/hitcounter.php";
if(file_exists($hitcounterphp)){include $hitcounterphp;}else{echo "hitcounterphp in directory $hitcounterphp could not be found <br/>";}
PhpMyAdmin结果。我没有选择要使用的主数据库
,但我的查询已为插入查询选择了其数据库
(来源:)
使用下面的代码进行Php测试,您会注意到在下面的示例中,我从未使用选择数据库
结果
(来源:)
在查询中包含数据库
的好处是,您可以进行跨服务器查询。只要你连接到数据库
,你的查询就会转到你指定的地方。这比用php中的函数选择一个主数据库
要有效得多。您没有提供任何与数据库实际连接相关的代码。@ramsai请看我的答案,您应该从根目录而不是从当前目录中包含。Regards@ramsai我用屏幕截图扩展了我的答案,用代码表示结果。我希望这能回答你的问题。我非常感谢你,你给了我一个很好的解释,我正在仔细考虑。:)没问题,我很高兴我能帮上忙,如果我的答案足够的话,如果你选择它作为最终答案,我将不胜感激。当做
<?php echo "<b>IncludeTo.php</b> was included!!"; ?>
CREATE TABLE IF NOT EXISTS `address` (
`AddressLine1` varchar(200) NOT NULL,
`City` varchar(200) NOT NULL,
`StateProvince` varchar(200) NOT NULL,
`CountryRegion` varchar(200) NOT NULL,
`PostalCode` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
echo "Connected to MySQL<br />";
$result = mysql_fetch_array(mysql_query("SELECT * FROM SalesLT.Address"));
echo "<pre>";print_r($result);echo"</pre>";
phpinfo();
?>