[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problem with sqlite database

Posted on 2013-05-13
6
Medium Priority
?
318 Views
Last Modified: 2013-05-13
Hello,

I am having a problem with the following code. While it executes ok and extremely fast, when the output is displayed, the browser still shows that something is loading for 2-3 seconds. I've tried it with both Firefox and Chrome and get the same results -> Immediate page execution and display of the contents but then waiting time for nothing to happen.

Any ideas?

Thanks a lot!

$file_db = new PDO('sqlite:sqlite/mydatabase.sqlite3');
echo "<table>";
$result = $file_db->query('SELECT * FROM hotels where longitude > 5 and latitude>43');
    foreach($result as $row)
    {
        echo "<tr><td>".$row['id']."</td>";
        echo "<td>".$row['name']."</td>";
        echo "<td>".$row['latitude']."</td>";
        echo "<td>".$row['longitude']."</td></tr>";
    }
    echo "</table>";
      
    //close the database connection
    unset($file_db);

Open in new window

0
Comment
Question by:infodigger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 39162313
greetings  infodigger, , I have used PDO for SQLite many times, and I have not ever had that problem, for the Most Part you do not need to Close a PDP SQLite connection, since it will stop when your PHP script ends anyway, But, if you do need to close it use
$file_db = null;

do not use -
  unset($file_db);

And this may be your problem, for the delay? ?
0
 

Author Comment

by:infodigger
ID: 39162473
Hi Slick812,

I tried to remove the unset and still I am having the same problem. I even added a few <br /> to the end of the page to see if they load and they do load but it looks like the page is still loading for some reason for an extra 2-3 seconds. It's driving me crazy:)
0
 
LVL 34

Expert Comment

by:Slick812
ID: 39162581
OK, I'll try and go through some possible reasons,
You do Not show any of the HTML required for web pages like -
<!DOCTYPE html>
 <html lang="en">
 <head><title>a title</title></head>
<body>


</body>
</html>

Without these, your browser may be waiting for more to get there? But does not seem like it should matter for 2 or 3 seconds?

It may be some sort of PDO delay, but I do not see why or how, try this instead -
$result = array();
$result[] = array(1, "John", 123, 456);
$result[] = array(2, "mary", 888, 999);

echo "<table>";
    foreach($result as $row)
    {
        echo "<tr><td>".$row['id']."</td>";
        echo "<td>".$row['name']."</td>";
        echo "<td>".$row['latitude']."</td>";
        echo "<td>".$row['longitude']."</td></tr>";
    }
    echo "</table>";

Open in new window


If this does Not delay, then it's a PDO delay
if this Does Delay, then its your server or the Domain Name relay that's causing the delay

But I can not know what to do since I do not have this problem? sorry, I only have some suggestions?
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:infodigger
ID: 39162622
Ok now I figured out that it's actually a server thing, not anything to do with SQLite. I tried the simplest page <?php echo "Hello World";?> and the same thing happened. So I am going to close this question. If you happen to have any idea why a server can do this, please let me know!

Thanks for the valuable help!
0
 
LVL 34

Expert Comment

by:Slick812
ID: 39162680
Almost all server PHP hosts that are established and have reliable setups, do not have this problem, , If you get the initial page very quickly, and then the server delays to finish the page It is likely  some problem in the server delivery. some Hosts that are cheep or  no longer maintained properly (about to go out of business) can have issues with slow performance.  You best should get in touch with your Host's Tech or administration people (chat, telephone, support ticket) and ask them about the delay.
0
 

Author Comment

by:infodigger
ID: 39162685
Ok I just figured it out... It was cause by an upgrade of php from 5.3.10 to 5.4.6. It seems that it was very unstable so I revert back to 5.3.10 and everything is working normally!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question