我有两张桌子。 (1)ENQUIRY
,(2)FOLLOW_UP
。我必须在视图中将FOLLOW_UP
的数据存储在MAX(VISITOR_ID)
。我的视图已成功创建,我可以在phpMyadmin
中查看数据。
(1)ENQUIRY
表
$enq = " CREATE TABLE IF NOT EXISTS ENQUIRY (
ID BIGINT PRIMARY KEY AUTO_INCREMENT ,
LONGDATE BIGINT,
UNAME VARCHAR(200) ,
ADDRESS VARCHAR(200) ,
STATE VARCHAR(60) ,
ZIP VARCHAR(20) ,
PHONE VARCHAR(100) ,
AGE INTEGER ,
SEX VARCHAR(6) ,
DOB_DATE INTEGER ,
DOB_MONTH INTEGER ,
DOB_YEAR INTEGER ,
MARITAL_STATUS VARCHAR(30),
BLOOD_GROUP VARCHAR(10),
EMAIL VARCHAR(200),
IS_MEMBER VARCHAR(3) DEFAULT 'NO' ,
REF_SOURCE VARCHAR(150) ,
REFERENCE VARCHAR(150),
LAST_FOLLOWUP BIGINT DEFAULT 0,
CREATE_BY VARCHAR(100),
CREATE_ON BIGINT,
SERVER INTEGER DEFAULT 0)";
(2)FOLLOW_UP
TABLE
$enq = " CREATE TABLE IF NOT EXISTS FOLLOW_UP (
ID BIGINT PRIMARY KEY AUTO_INCREMENT ,
VISITOR_ID BIGINT ,
VISITOR_NAME VARCHAR(200) ,
LONGDATE BIGINT ,
FEED_BACK VARCHAR(200) ,
NEXT_CONTACT BIGINT ,
FEED_BACK_SUMMARY VARCHAR(80) ,
FOLLOWUP_BY VARCHAR(80),
SERVER INTEGER DEFAULT 0)";
我的观点如下:
$enq = "CREATE OR REPLACE VIEW F_TOFOLLOW
AS SELECT
FOLLOW_UP.ID,
FOLLOW_UP.LONGDATE,
FOLLOW_UP.VISITOR_ID,
ENQUIRY.UNAME,
FOLLOW_UP.FEED_BACK,
FOLLOW_UP.FEED_BACK_SUMMARY,
FOLLOW_UP.FOLLOWUP_BY,
FOLLOW_UP.NEXT_CONTACT,
ENQUIRY.CREATE_BY,
ENQUIRY.IS_MEMBER
FROM FOLLOW_UP
INNER JOIN ENQUIRY ON FOLLOW_UP.VISITOR_ID = ENQUIRY.ID
WHERE FOLLOW_UP.ID = (SELECT MAX(ID) FROM
FOLLOW_UP F WHERE F.VISITOR_ID = FOLLOW_UP.VISITOR_ID)";
现在我正在尝试从视图中运行查询:
$Q = "SELECT COUNT(*) AS TOFOLLOW FROM F_TOFOLLOW";
我尝试执行的任何查询都非常非常慢。我大部分时间都得到了:
SQLSTATE [HY000]:常规错误:2006 MySQL服务器已经消失
有人建议我在mysql配置中更新max_allowed_packet
,但在共享主机中无法这样做。
类似的观点运行良好。我的代码出了什么问题?有什么方法可以解决这个问题吗?