Hi new to PHP...very new..I created some pages for a class I'm taking in php. Eight pages with a query and dynamic results table on each page. They all work fine but the problem is they only work locally. We have a remote server for school use, but of course when I view the query pages remotely, they display blank pages I assume because the db connection is not correct.

Is there a way to have two database connections for a single query? Is that normal in order to test locally and work remotely as well? If so hwo would I go about adding a second db connection to the same query?

Here is the connection code for my local db:

<?php require_once('Connections/student.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_student, $student);
$query_Recordset1 = "SELECT tblswimwear.Model, tblswimwear.Style, tblswimwear.Color, tblswimwear.`Size`, tblswimwear.QuantityInStock  FROM tblswimwear ORDER BY tblswimwear.Color, tblswimwear.`Size`DESC";
$Recordset1 = mysql_query($query_Recordset1, $student) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

Thanks for any suggestions in advance.

btw I know the remote db server location.

If you want to use two different DB connections, you need to start using the mysqli functions instead of the mysql functions. In the mysqli functions you need to specify which database connection you use to execute the queries and functions. Also, when selecting a database always use a or die() statement behind it:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die("Could not connect to MySQL.");
$dbselect = mysql_select_db("mysql_database", $link) or die("Could not select MySQL database.");

~G

Ok Im very new to php, so I'm still confused as to what you suggested Graphix. Is it normal to have to configure a local connection to the db as well as a remote connection?

Also the two lines of code you gave me, what would I replace with that? and if I do replace, then does my local db connection get lost?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.