简体   繁体   中英

Undefined variable when code works in hosted server

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 (eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM