doutui6644 2013-07-26 04:35
浏览 38
已采纳

代码在托管服务器中工作时未定义的变量

Trying to help someone with their php based site, I cannot run it locally as I get errors for 'Undefined variable: dbhost' etc. when trying to use any page that connects to mysql.

dbConfig.php:

<?

$dbhost="HOST"; // Host name 
$dbusername="USER"; // Mysql username 
$dbuserpass="PASS"; // Mysql password 
$dbname="NAME"; // Database name 

?>

Excerpt from including php file (e.g. login.php):

include_once ("../include/dbConfig.php");
$db_handle = mysql_connect($dbhost, $dbusername, $dbuserpass) or die(mysql_error());

This works fine in his hosted server solution on PHP 5.1. My local setup is Apache & PHP 5.5 on Windows 7.

  • 写回答

1条回答 默认 最新

  • dongling2038 2013-07-26 04:35
    关注

    To use the shorthand <? for starting php comment blocks, you need to enable the directive short_open_tag in php.ini.

    The default has changed for new installations since 5.3, see: <? ?> tags not working in php 5.3.1

    It is recommended not to use them and change older code to use the full <?php syntax rather than enabling this tag - PEAR coding standards for tags. There are also some rumors that they would be deprecated for PHP 6, but these seem unfounded as I was unable to find any official source.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了