找不到MySQL表,但它存在

时间:2014-04-01 17:48:29

标签: php mysql

我正在开发一个包含HTML5,PHP和MySQL的网络应用程序。我已经在使用MAMP的本地服务器上进行了测试,它运行正常。

现在我已将所有文件上传到Web服务器并导出MySQL数据库。我已经更改了数据库连接文件,以实现web mysql服务器的连接参数。

我正在测试Web服务器上的应用程序并且它运行正常,但在一个文件中我收到的错误并非在本地服务器上发生。调用文件后,Web浏览器上出现错误消息:

enter image description here

我不知道为什么它会抛出错误,然后表tb.Clientes确实存在于数据库中,还有其他页面使用该表并且没有抛出错误。

我怎样才能获得抛出错误的代码行?我不是专业的PHP程序员。

已更新

太长了,但我现在要包含一些代码:

<?php require_once('Connections/conexion.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "index.html";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "3,2,1";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "accesonoautorizado.html";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?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;
}
}

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;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = sprintf("SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_presupmx = "-1";
if (isset($_GET['id'])) {
  $colname_presupmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_presupmx = sprintf("SELECT * FROM tbpresupuestosmx WHERE int_obra = %s AND tbpresupuestosmx.int_moneda =1", GetSQLValueString($colname_presupmx, "int"));
$presupmx = mysql_query($query_presupmx, $conexion) or die(mysql_error());
$row_presupmx = mysql_fetch_assoc($presupmx);
$totalRows_presupmx = mysql_num_rows($presupmx);

$colname_presudollar = "-1";
if (isset($_GET['id'])) {
  $colname_presudollar = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_presudollar = sprintf("SELECT * FROM tbpresupuestosmx WHERE int_obra = %s AND tbpresupuestosmx.int_moneda =2", GetSQLValueString($colname_presudollar, "int"));
$presudollar = mysql_query($query_presudollar, $conexion) or die(mysql_error());
$row_presudollar = mysql_fetch_assoc($presudollar);
$totalRows_presudollar = mysql_num_rows($presudollar);

$vardato_sumaingresos = "0";
if (isset($_GET['id'])) {
  $vardato_sumaingresos = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_sumaingresos = sprintf("SELECT SUM(tbingresos.estimacion) AS sumaestimacion, SUM(tbingresos.importeiva) AS sumaimporteiva, SUM(tbingresos.fondogarantia) AS sumafondogarantia , SUM(tbingresos.importefactura) AS  sumaimportefactura, SUM(tbingresos.totalcobrado) AS  sumatotalcobrado FROM tbingresos WHERE tbingresos.obra = %s AND tbingresos.moneda = 1", GetSQLValueString($vardato_sumaingresos, "int"));
$sumaingresos = mysql_query($query_sumaingresos, $conexion) or die(mysql_error());
$row_sumaingresos = mysql_fetch_assoc($sumaingresos);
$totalRows_sumaingresos = mysql_num_rows($sumaingresos);

$vardato_sumaingresos2 = "0";
if (isset($_GET['id'])) {
  $vardato_sumaingresos2 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_sumaingresos2 = sprintf("SELECT SUM(tbingresos.estimacion) AS sumaestimacion, SUM(tbingresos.importeiva) AS sumaimporteiva, SUM(tbingresos.fondogarantia) AS sumafondogarantia , SUM(tbingresos.importefactura) AS  sumaimportefactura, SUM(tbingresos.totalcobrado) AS  sumatotalcobrado FROM tbingresos WHERE tbingresos.obra = %s AND tbingresos.moneda = 2", GetSQLValueString($vardato_sumaingresos2, "int"));
$sumaingresos2 = mysql_query($query_sumaingresos2, $conexion) or die(mysql_error());
$row_sumaingresos2 = mysql_fetch_assoc($sumaingresos2);
$totalRows_sumaingresos2 = mysql_num_rows($sumaingresos2);

$vardato_materialesgastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_materialesgastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_materialesgastosmxn = sprintf("SELECT SUM(importe) as materiales FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=1 AND tbgastos.moneda=1", GetSQLValueString($vardato_materialesgastosmxn, "int"));
$materialesgastosmxn = mysql_query($query_materialesgastosmxn, $conexion) or die(mysql_error());
$row_materialesgastosmxn = mysql_fetch_assoc($materialesgastosmxn);
$totalRows_materialesgastosmxn = mysql_num_rows($materialesgastosmxn);

$vardato_manoobragastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_manoobragastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_manoobragastosmxn = sprintf("SELECT SUM(importe) as manoobra FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=3 AND tbgastos.moneda=1", GetSQLValueString($vardato_manoobragastosmxn, "int"));
$manoobragastosmxn = mysql_query($query_manoobragastosmxn, $conexion) or die(mysql_error());
$row_manoobragastosmxn = mysql_fetch_assoc($manoobragastosmxn);
$totalRows_manoobragastosmxn = mysql_num_rows($manoobragastosmxn);

$vardato_herramientasgastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_herramientasgastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_herramientasgastosmxn = sprintf("SELECT SUM(importe) as herramientas FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=5 AND tbgastos.moneda=1", GetSQLValueString($vardato_herramientasgastosmxn, "int"));
$herramientasgastosmxn = mysql_query($query_herramientasgastosmxn, $conexion) or die(mysql_error());
$row_herramientasgastosmxn = mysql_fetch_assoc($herramientasgastosmxn);
$totalRows_herramientasgastosmxn = mysql_num_rows($herramientasgastosmxn);

$vardato_equipogastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_equipogastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_equipogastosmx = sprintf("SELECT SUM(importe) as equipo FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=6 AND tbgastos.moneda=1", GetSQLValueString($vardato_equipogastosmx, "int"));
$equipogastosmx = mysql_query($query_equipogastosmx, $conexion) or die(mysql_error());
$row_equipogastosmx = mysql_fetch_assoc($equipogastosmx);
$totalRows_equipogastosmx = mysql_num_rows($equipogastosmx);

$colname_Recordset2 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset2 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset2 = sprintf("SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset2, "int"));
$Recordset2 = mysql_query($query_Recordset2, $conexion) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

$vardato_utilidadgastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_utilidadgastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_utilidadgastosmx = sprintf("SELECT SUM(importe) as utilidad FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=7 AND tbgastos.moneda=1", GetSQLValueString($vardato_utilidadgastosmx, "int"));
$utilidadgastosmx = mysql_query($query_utilidadgastosmx, $conexion) or die(mysql_error());
$row_utilidadgastosmx = mysql_fetch_assoc($utilidadgastosmx);
$totalRows_utilidadgastosmx = mysql_num_rows($utilidadgastosmx);

$vardato_admingastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_admingastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_admingastosmx = sprintf("SELECT SUM(importe) as administrativos FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=8 AND tbgastos.moneda=1", GetSQLValueString($vardato_admingastosmx, "int"));
$admingastosmx = mysql_query($query_admingastosmx, $conexion) or die(mysql_error());
$row_admingastosmx = mysql_fetch_assoc($admingastosmx);
$totalRows_admingastosmx = mysql_num_rows($admingastosmx);

$vardato_materialesgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_materialesgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_materialesgastosusd = sprintf("SELECT SUM(importe) as materiales FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=1 AND tbgastos.moneda=2", GetSQLValueString($vardato_materialesgastosusd, "int"));
$materialesgastosusd = mysql_query($query_materialesgastosusd, $conexion) or die(mysql_error());
$row_materialesgastosusd = mysql_fetch_assoc($materialesgastosusd);
$totalRows_materialesgastosusd = mysql_num_rows($materialesgastosusd);

$vardato_manobragastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_manobragastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_manobragastosusd = sprintf("SELECT SUM(importe) as manoobra FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=3 AND tbgastos.moneda=2", GetSQLValueString($vardato_manobragastosusd, "int"));
$manobragastosusd = mysql_query($query_manobragastosusd, $conexion) or die(mysql_error());
$row_manobragastosusd = mysql_fetch_assoc($manobragastosusd);
$totalRows_manobragastosusd = mysql_num_rows($manobragastosusd);

$vardato_herramientasgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_herramientasgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_herramientasgastosusd = sprintf("SELECT SUM(importe) as herramientas FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=5 AND tbgastos.moneda=2", GetSQLValueString($vardato_herramientasgastosusd, "int"));
$herramientasgastosusd = mysql_query($query_herramientasgastosusd, $conexion) or die(mysql_error());
$row_herramientasgastosusd = mysql_fetch_assoc($herramientasgastosusd);
$totalRows_herramientasgastosusd = mysql_num_rows($herramientasgastosusd);

$vardato_equipogastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_equipogastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_equipogastosusd = sprintf("SELECT SUM(importe) as equipo FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=6 AND tbgastos.moneda=2", GetSQLValueString($vardato_equipogastosusd, "int"));
$equipogastosusd = mysql_query($query_equipogastosusd, $conexion) or die(mysql_error());
$row_equipogastosusd = mysql_fetch_assoc($equipogastosusd);
$totalRows_equipogastosusd = mysql_num_rows($equipogastosusd);

$vardato_utilidadgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_utilidadgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_utilidadgastosusd = sprintf("SELECT SUM(importe) as utilidad FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=7 AND tbgastos.moneda=2", GetSQLValueString($vardato_utilidadgastosusd, "int"));
$utilidadgastosusd = mysql_query($query_utilidadgastosusd, $conexion) or die(mysql_error());
$row_utilidadgastosusd = mysql_fetch_assoc($utilidadgastosusd);
$totalRows_utilidadgastosusd = mysql_num_rows($utilidadgastosusd);

$vardato_admingastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_admingastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_admingastosusd = sprintf("SELECT SUM(importe) as administrativos FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=8 AND tbgastos.moneda=2", GetSQLValueString($vardato_admingastosusd, "int"));
$admingastosusd = mysql_query($query_admingastosusd, $conexion) or die(mysql_error());
$row_admingastosusd = mysql_fetch_assoc($admingastosusd);
$totalRows_admingastosusd = mysql_num_rows($admingastosusd);
?>

3 个答案:

答案 0 :(得分:1)

一步一步的方法。 检查任何包含文件 检查服务器和用户名密码等连接参数。 检查表和数据库名称

答案 1 :(得分:1)

1.由于MySQL使用目录和文件来存储数据库和表,如果数据库和表名位于具有区分大小写的文件名的文件系统上,则它们区分大小写。

2.即使对于不区分大小写的文件系统,例如在Windows上,对查询中给定表的所有引用都必须使用相同的字母大写

答案 2 :(得分:1)

表名非常区分大小写。从您的代码中我看到您与表tbClientestbclientes进行了联接。

例如:

"SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset1, "int"));