简体   繁体   中英

Magento Database Connection Problem

I'm working on Magento Enterprise v1.9.0.0. I need to connect to the database and run SQL directly to query tables.

Here is what I've used to do that.

    $query = "...SQL QUERY...";
    $databaseConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $result = $databaseConnection->fetchAll($query);

I have Magento Community v1.4.1.1 and Magento Enterprise v1.9.0.0 installed on my local computer. So in order to test, I've run the above code on my local machine, and all works fine.

But it doesn't work on live server. Magento Enterprise v1.9.0.0 is installed on the live server and online store is running. All works fine on live store and nothing special happens.

But I've uploaded this code to the server, it doesn't work. And further, I can't get any PHP/MySQL error message.

Here is more detailed codes which I used to track run time.

    // Debug Output
    $this->OutputDebugLogo("<br/>");
    $this->OutputDebugLogo("<br/><h3>Query : </h3>#", $query);

    $databaseConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $result = $databaseConnection->fetchAll($query);

    // Debug Output
    $this->OutputDebugLogo("<br/><h3>Result : </h3>#", $result);
    $this->OutputDebugLogo("<br/>");

I can be sure there is no error on SQL statement. And the function OutputDebugLogo() is made by myself to output debug message with variables.

Here is what I've got after running this script on my local machine.

    Query :
    ' SELECT ... FROM ... WHERE ... '

    Result:
    array ( 0 => array ( 'items' => 'a:2:{s:3:"MEN";a:11:{s:9:... )

And here you can see what I've got on the live server.

    Query :
    ' SELECT ... FROM ... WHERE ... '

As you can see, there is no PHP/MySQL error message. And we can say the script wass stopped running at database code block.

I can't make any progress to find the main cause. Why did it happen? Can anyone know it?

I'm really looking forward to getting help from everyone.

Best Regards. Floppy

I ran your script on Magento Enterprise 1.9.0.0 and it worked with no problems, so there doesn't appear to be any problem with the script itself. what is your query? It's likely that there is a schema difference between the two versions that you aren't taking into account.

Hope that helps!

Thanks, Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM