php - 未找到 MySQL 表,但它存在

标签 php mysql

我正在使用 HTML5、PHP 和 MySQL 开发网络应用程序。我已经使用 MAMP 在本地服务器上进行了测试,它运行良好。

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

我正在 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);
?>

最佳答案

表名几乎区分大小写。从您的代码中,我看到您对表 tbClientestbclientes 进行了连接。

例如:

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

关于php - 未找到 MySQL 表,但它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793168/

相关文章:

php - 如何减小数据库大小?

mysql - 如何从 PhpMyAdmin 取消复制表

php - HTTP 转义字符、PHP、CALDAV

php - 您可以使用 MySQL 运行的 PHP 查询有最大数量限制吗?

php - Facebook 图形 API + PHP SDK : get the URL of the large user picture

PHP for 循环有时过早停止

mysql - 如何使用 Google Compute Engine 保持持久 SQL 代理 Unix 套接字

php - 优化重复密码检查功能

php - 它不会在数据库中插入值

mysql - SQL/Rails 返回一组记录中唯一值的计数