CI mysql_result中的内存泄漏问题

时间:2016-06-28 05:09:15

标签: php codeigniter

我不明白为什么会收到以下错误:

Fatal error: Out of memory (allocated 10747904) (tried to allocate 93 bytes) in /home/project/public_html/system/database/drivers/mysql/mysql_result.php on line 167

phpinfo()详情

                localvalue mastervalue
memory_limit    4028M      4028M

SQL

SELECT 
    p.*,l.*,u.*,ct.*,t.*,pc.*
FROM 
    tbl_Product AS p 
    JOIN tbl_DistributorLocationId AS l ON p.fk_LocationId = l.pk_DistributorLocationId 
    JOIN tbl_Manufacturer AS m ON p.fk_Manufacturer = m.pk_ManufacturerId 
    LEFT JOIN tbl_Color AS c ON p.fk_Colors = c.pk_ColorId 
    LEFT JOIN tbl_Texture AS t ON p.fk_Texture = t.pk_TextureId 
    LEFT JOIN tbl_ProductLine AS pl ON p.fk_ProductLine = pl.pk_ProductLineId 
    LEFT JOIN tbl_States AS s ON l.fk_StateId = s.pk_StateId 
    LEFT JOIN tbl_Users AS u ON l.fk_UserId = u.pk_UserId 
    LEFT JOIN tbl_UserType AS ut ON u.fk_UserTypeId = ut.pk_UserTypeId 
    LEFT JOIN tbl_ProductCategories AS pc ON p.fk_CategoryId = pc.pk_CategoryId 
    LEFT JOIN tbl_CategoryType AS ct ON pc.fk_CategoryTypeId = ct.pk_CategoryTypeId 
where 
    1 = 1 
    AND p.boolean_status = 1 
ORDER BY 
    LOCATE('', varchar_Title), 
    LOCATE('', varchar_ProductLineText), 
    LOCATE('', varchar_ColorName), 
    LOCATE('', varchar_TextureName), 
    LOCATE('', text_Description), 
    LOCATE('', varchar_CategoryName), 
    LOCATE('', varchar_CategoryTypeName)

来自phpmyadmin的结果

39706 total, Query took 1.2748 seconds.

2 个答案:

答案 0 :(得分:0)

您可以执行以下任一操作:

  1. 如果您有权访问PHP.ini文件,请更改PHP.ini中的行

    memory_limit = 128M;

  2. 如果您无法访问PHP.ini,请尝试将其添加到.htaccess文件中:

    php_value memory_limit 128M

答案 1 :(得分:0)

仅获取应用程序中所需的记录,而不是从表中获取所有数据。

<强>之前

SELECT 
    p.*,l.*,u.*,ct.*,t.*,pc.*
FROM 
    tbl_Product AS p 
    JOIN tbl_DistributorLocationId AS l ON p.fk_LocationId = l.pk_DistributorLocationId 
    JOIN tbl_Manufacturer AS m ON p.fk_Manufacturer = m.pk_ManufacturerId 
    LEFT JOIN tbl_Color AS c ON p.fk_Colors = c.pk_ColorId 
    LEFT JOIN tbl_Texture AS t ON p.fk_Texture = t.pk_TextureId 
    LEFT JOIN tbl_ProductLine AS pl ON p.fk_ProductLine = pl.pk_ProductLineId 
    LEFT JOIN tbl_States AS s ON l.fk_StateId = s.pk_StateId 
    LEFT JOIN tbl_Users AS u ON l.fk_UserId = u.pk_UserId 
    LEFT JOIN tbl_UserType AS ut ON u.fk_UserTypeId = ut.pk_UserTypeId 
    LEFT JOIN tbl_ProductCategories AS pc ON p.fk_CategoryId = pc.pk_CategoryId 
    LEFT JOIN tbl_CategoryType AS ct ON pc.fk_CategoryTypeId = ct.pk_CategoryTypeId 
where 
    1 = 1 
    AND p.boolean_status = 1 
ORDER BY 
    LOCATE('', varchar_Title), 
    LOCATE('', varchar_ProductLineText), 
    LOCATE('', varchar_ColorName), 
    LOCATE('', varchar_TextureName), 
    LOCATE('', text_Description), 
    LOCATE('', varchar_CategoryName), 
    LOCATE('', varchar_CategoryTypeName)

之后

SELECT 
    pc.pk_CategoryId, 
    pc.varchar_CategoryName, 
    c.pk_ColorId, 
    c.varchar_ColorName, 
    m.varchar_Title, 
    m.pk_ManufacturerId, 
    u.varchar_CompanyName, 
    u.pk_UserId, 
    pl.pk_ProductLineId, 
    pl.varchar_ProductLineText
FROM 
    tbl_Product AS p 
    JOIN tbl_DistributorLocationId AS l ON p.fk_LocationId = l.pk_DistributorLocationId 
    JOIN tbl_Manufacturer AS m ON p.fk_Manufacturer = m.pk_ManufacturerId 
    LEFT JOIN tbl_Color AS c ON p.fk_Colors = c.pk_ColorId 
    LEFT JOIN tbl_Texture AS t ON p.fk_Texture = t.pk_TextureId 
    LEFT JOIN tbl_ProductLine AS pl ON p.fk_ProductLine = pl.pk_ProductLineId 
    LEFT JOIN tbl_States AS s ON l.fk_StateId = s.pk_StateId 
    LEFT JOIN tbl_Users AS u ON l.fk_UserId = u.pk_UserId 
    LEFT JOIN tbl_UserType AS ut ON u.fk_UserTypeId = ut.pk_UserTypeId 
    LEFT JOIN tbl_ProductCategories AS pc ON p.fk_CategoryId = pc.pk_CategoryId 
    LEFT JOIN tbl_CategoryType AS ct ON pc.fk_CategoryTypeId = ct.pk_CategoryTypeId 
where 
    1 = 1 
    AND p.boolean_status = 1 
ORDER BY 
    LOCATE('', varchar_Title), 
    LOCATE('', varchar_ProductLineText), 
    LOCATE('', varchar_ColorName), 
    LOCATE('', varchar_TextureName), 
    LOCATE('', text_Description), 
    LOCATE('', varchar_CategoryName), 
    LOCATE('', varchar_CategoryTypeName)