You are here:  » Warning: mysql_select_db(): supplied argument is not a valid


Warning: mysql_select_db(): supplied argument is not a valid

Submitted by baggagepin on Tue, 2010-06-15 15:44 in

Hi all,

I am have a problem with an SQL Select query. When I run the code below I get the following error. Can anyone see what I am doing wrong.

Error:
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/fmydomain.com/httpdocs/lgw/lgwfids.php on line 87

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/mydomain.com/httpdocs/lgw/lgwfids.php on line 91

<?php
require("/var/www/vhosts/mydomain.com/httpdocs/MagicParser.php");
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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;
}
}
function myRecordHandler($record)
  {
  global $id, $AODBUniqueID, $FIDSFlightActive, $CarrierCode, $FlightNumber, $FlightSuffix, $FlightNoComplete, $ArrivalOrDeparture, $FlightSuffix, $TerminalCode, $GateNumber, $IATALocationCode, $PublicLocationName,$ScheduledDateTime, $EstimatedDateTime, $StatusMessageText, $ArrDep, $StandAllocations, $City2, $sql ;
$ArrDep = mysql_real_escape_string($record["ArrDep"]);
$CarrierCode = mysql_real_escape_string($record["Airline"]);
$FlightNumber = mysql_real_escape_string($record["Airline"]."".$record["FltNo"]);
$ScheduledDateTime = mysql_real_escape_string($record["Time"]);
$EstimatedDateTime = mysql_real_escape_string($record["Est"]);
$PublicLocationName = mysql_real_escape_string($record["City1"]);
$City2 = mysql_real_escape_string($record["City2"]);
$IATALocationCode = mysql_real_escape_string($record["Iata"]);
$Stat = mysql_real_escape_string($record["Stat"]);
$GateNumber = mysql_real_escape_string($record["Gate"]);
$TerminalCode = mysql_real_escape_string($record["Term"]);
$StandAllocations = mysql_real_escape_string($record["Stand"]);
$Date = mysql_real_escape_string($record["Date"]);
   $FlightDate = $Date ;
$timeflag = date("Y-m-d H:i:s");
$AODBUniqueID = $FlightNumber."".$ScheduledDateTime;
mysql_select_db("database", $con);
$result = mysql_query("SELECT * FROM flightdata WHERE AODBUniqueID = " . $AODBUniqueID . "");
while($row = mysql_fetch_array($result))
  {
  echo $row['CarrierCode'] . " " . $row['FlightNumber'];
  echo "<br />";
  }
}
$result = MagicParser_parse("/var/www/vhosts/mydomain.com/httpdocs/xml/LGW.CSV","myRecordHandler","csv|44|1|0");

Submitted by support on Wed, 2010-06-16 06:25

Hi,

I think it's just that $con is not declared as global at the top of your myRecordHandler() function. You could simply add it to the list of globals that you're already declaring, or if you're not sure, replace

function myRecordHandler($record)
  {

...with:

function myRecordHandler($record)
  {
    global $con;

Hope this helps!
Cheers,
David.