Need to define global variable for function db_connect
Posted: Mon Dec 15, 2008 2:19 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have a website that works perfect in localmode, im not a developer, but when i uploaded to the remote server doesn´t connect to the db. I have been told that the global variable has to be define wiht the correct data (dbhost, dbuserid, dbpasswd) of the remote server.
This is the code that works with local server:
This is what i did affterwards,
I only added this line: $user="userid",$pwd="password";
but im not sure i did correctly.
userid and password, will be replaced by the proper values at the time of uploading.
Thanks
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have a website that works perfect in localmode, im not a developer, but when i uploaded to the remote server doesn´t connect to the db. I have been told that the global variable has to be define wiht the correct data (dbhost, dbuserid, dbpasswd) of the remote server.
This is the code that works with local server:
Code: Select all
function db_connect()
{
global $host,$user,$pwd,$errstr,$sys_dbname,$port,$bSubqueriesSupported;
$strhost=$host;
if($port && $port!=3306)
$strhost=$strhost.":".$port;
$conn = mysql_connect($strhost,$user,$pwd);
if (!$conn || !mysql_select_db($sys_dbname,$conn))
{
trigger_error(mysql_error(), E_USER_ERROR);
}
$mysqlversion = "4";
$res = @mysql_query("SHOW VARIABLES LIKE 'version'",$conn);
if($row=@mysql_fetch_array($res,MYSQL_ASSOC))
$mysqlversion = $row["Value"];
if(substr($mysqlversion,0,1)<="4")
$bSubqueriesSupported=false;
return $conn;
Code: Select all
<?php
function db_connect()
{
global $host,$user,$pwd,$errstr,$sys_dbname,$port,$bSubqu eriesSupported;
$strhost=$host,$user="userid",$pwd="contraseña";
if($port && $port!=3306)
$strhost=$strhost.":".$port;
$conn = mysql_connect($strhost,$user,$pwd);
if (!$conn || !mysql_select_db($sys_dbname,$conn))
{
trigger_error(mysql_error(), E_USER_ERROR);
}
$mysqlversion = "4";
$res = @mysql_query("SHOW VARIABLES LIKE 'version'",$conn);
if($row=@mysql_fetch_array($res,MYSQL_ASSOC))
$mysqlversion = $row["Value"];
if(substr($mysqlversion,0,1)<="4")
$bSubqueriesSupported=false;
return $conn;
}
but im not sure i did correctly.
userid and password, will be replaced by the proper values at the time of uploading.
Thanks
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: