Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 5

PHP database search works on XAMPP but not web hosting server?

Hello,

I'm working on a personal webpage with very limited knowledge of html so please bear with me.

I'm trying to search and display results from a sql database using php. While building and testing my code on XAMPP, the following code worked just fine:

$con = new PDO('sqlite:database.db');

$search=(!empty($_POST['search']) ? $_POST['search'] : null);

$query = $con->query("select * from Directory where Name LIKE '$search'");

$results = $query->fetchAll(PDO::FETCH_ASSOC);

I have an input box named "search", and I used a .db file named database.

However, my search function fails to work when I uploaded it to my web hosting server. I've added echo functions to see where the code stops running (not really sure if this is the correct way to find codes that don't work) and anything beyond $results don't seem to be running at all on my php page.

I've tried changing around the coding to the best of my ability, but I'm at a loss.

Is it possible that my web hosting server doesn't allow me to use a .db file? I did set the server to php 7, is my code not compatible with php7? I cannot seem to figure out why the same code works on XAMPP, but not on my hosting server. My XAMPP does runs in 5.6, but my hosting server only offers 5.2, 5.3, 5.5, and 7.

Any help would be greatly appreciated.

Thank you.

1 Answer

Relevance
  • 4 years ago

    Most likely because you are using sqlite rather than mysql.

    That's external to PHP and system-dependent.

    The M in LAMP (or XAMPP) is MySQL; that's what _will_ work with it.

    Use the "mysqli" functions for access to the database.

    http://php.net/manual/en/book.mysqli.php

Still have questions? Get your answers by asking now.