当我使用这个SQL查询时:
$myquery = mysql_query(" create table q_mem_sur as SELECT Count(*) As rowa,
member.Ssurname,
Sum(Case When ((member.status = '1')) Then 1 Else 0 End) As Status11
From member
Group By member.Ssurname
Order By rowa Desc");
在MySQL GUI工具中,它可以工作,但是当用PHP运行它时会发出警告:
Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\wamp\www\mayor_T\prepare.php on line 78
我尝试更改php.ini
中的配置但是我应该更改的关键词是什么?
这是我测试它可以运行的所有sql语句的代码
<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "ageyearinfo.php" ?>
<?php
$con = mysql_connect(EW_CONN_HOST,EW_CONN_USER,EW_CONN_PASS);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_set_charset('utf8',$con);
$charset = mysql_client_encoding($con);
$db_selected = mysql_select_db(EW_CONN_DB, $con);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
echo "connect database and use The current character set is: $charset\n";
$myquery = mysql_query("UPDATE `member` SET `amphurecode`= SUBSTRING(member.own,3,4)");
if (!$myquery)
{
die('can not update amphurecode ' . mysql_error());
}
$myquery = mysql_query("UPDATE `member` SET `provincecode`= SUBSTRING(member.own,3,2)");
if (!$myquery)
{
die('can not update province code ' . mysql_error());
}
echo "update amporecode and province\n";
$dropT = mysql_query("drop table if exists q_mem_tim");
if (!$dropT)
{
die('Could not delete ' . mysql_error());
}
$myquery = mysql_query(" create table q_mem_tim as SELECT member.idmember, member.own, member.provincecode, province.PROVINCE_NAME, member.amphurecode, amphur.AMPHUR_NAME, member.Sname, member.Ssurname, member.Hno, member.Moo, member.Sex, member.tambol, member.dateofbirth, member.migratedate, Year( Current_Date( ) ) - Year( member.dateofbirth ) AS y, DATEDIFF('2011-08-01',(migratedate)) AS d
FROM member
LEFT JOIN amphur ON ( member.amphurecode
= amphur.AMPHUR_CODE )
LEFT JOIN province ON member.provincecode
= province.PROVINCE_CODE");
if (!$myquery)
{
die('can not create q_member ' . mysql_error());
}
echo "create q_mem_tim \n";
$drop_q_mem_sur = mysql_query("drop table if exists q_mem_sur");
if (!$drop_q_mem_sur)
{
die('Could not delete q_mem_sur ' . mysql_error());
}
$myquery = mysql_query(" create table q_mem_sur as SELECT Count(*) As rowa,
member.Ssurname,
Sum(Case When ((member.status = '1')) Then 1 Else 0 End) As Status11
From member
Group By member.Ssurname
Order By rowa Desc");
if (!$myquery)
{
die('can not create myquery ' . mysql_error());
}
echo "create q_mem_sur \n";
$dropT = mysql_query("drop table if exists q_mem_hno");
if (!$dropT)
{
die('Could not delete table q_mem_hno ' . mysql_error());
}
$myquery = mysql_query(" create table q_mem_hno as select member.Hno, member.Moo, member.tambol, COUNT( member.Hno ) AS cntHno, COUNT(DISTINCT member.Ssurname) as NoSur
FROM member
GROUP BY member.Hno, member.Moo, member.tambol
ORDER BY cntHno DESC ");
if (!$myquery)
{
die('can not create q_mem_hno ' . mysql_error());
}
echo "create q_mem_hno \n";
$dropT = mysql_query("drop table if exists q_pro_ori");
if (!$dropT)
{
die('Could not delete table q_pro_ori ' . mysql_error());
}
$myquery = mysql_query(" create table q_pro_ori as Select member.provincecode,
count(*) As cnt From member Group By member.provincecode Order By cnt Desc ");
if (!$myquery)
{
die('can not create q_pro_ori' . mysql_error());
}
echo "create q_pro_ori \n";
$dropT = mysql_query("drop table if exists q_am_ori");
if (!$dropT)
{
die('Could not delete table q_am_ori ' . mysql_error());
}
$myquery = mysql_query("create table q_am_ori as Select member.amphurecode, member.provincecode, count(*) As cnt From member Group By member.amphurecode, member.provincecode Order By cnt Desc ");
if (!$myquery)
{
die('can not create q_am_ori ' . mysql_error());
}
echo "create q_am_ori \n";
$dropT = mysql_query("drop table if exists Sur_Hno_");
if (!$dropT)
{
die('Could not delete table Sur_Hno_ ' . mysql_error());
}
$myquery = mysql_query("create table Sur_Hno_ as SELECT count( * ) , Ssurname, q_mem_tim.Hno, q_mem_tim.Moo, q_mem_tim.tambol
FROM q_mem_tim
GROUP BY q_mem_tim.Ssurname, q_mem_tim.Hno, q_mem_tim.Moo, q_mem_tim.tambol
ORDER BY count( * ) DESC
");
if (!$myquery)
{
die('can not create q_am_ori ' . mysql_error());
}
echo "process finish";
?>