doutui6644 2013-07-26 12: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 12: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.

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了