1

I have this code:

        <?php
    require_once($_SERVER['DOCUMENT_ROOT'] . '/framework/classes/DBConnection.php');

    define('DB_NAME', 'thename');
    define('DB_HOST', 'thehost.com');
    define('DB_USER', 'user');
    define('DB_PASSWORD', 'pwd');




// Connect to database
function db_connect() {
    return DBConnection::GetConnection();
}


function getMeta($conn) {
    $sql = "SELECT order_ref FROM orders LIMIT 0,1";
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $stmt->bind_result($ref);
    $stmt->fetch();
    $stmt->close();
    return $ref;
}

function getMeta2($conn, $page) {
    $sql = "SELECT meta FROM pages_meta WHERE pageid = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param('s', $page);
    $stmt->execute();
    $stmt->bind_result($meta);
    $stmt->fetch();
    $stmt->close(); 
    return $meta;
}


$conn = db_connect();
?>
</head>
<body>
<h1>Hello World</h1>
<?php echo getMeta($conn); ?>
<br>
<?php echo getMeta2($conn, "homepage"); ?>
</body>
</html>
<?php
$conn->close();
?>

Output:

    Hello World

1407324725

Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 4294967296 bytes) in /home/rnsalarm/co2supermarket.co.uk/test.php on line 41

Huh???! I get an out of memory exception when running this SQL:

SELECT meta FROM pages_meta WHERE pageid = ?

The table only has 15 rows, and even then it has indexes. Any ideas what's going on? The rest of the website works fine, just this one query it throws a wobbler. To add some more mystery; it works fine if I run in on my local dev computer, connecting to the same DB, only when it's uploaded to the server do I get this problem. It's very odd. Like I say, the rest of the website works absolutely fine.

Any thoughts what's going on here?

1 Answer 1

2

Ah ha! The datatype was longtext - seems my host doesn't like longtext - changed to a varchar instead and voila!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.