Updating Error

Come here for help or to post comments on Sphider
User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Tue Dec 11, 2018 9:59 pm

Just looking ahead in the event second part of the snippet (the query) fails to produce "Success"....

Just on a hunch, try this snippit:
<?php
$database="sphider";
$mysql_user = "root";
$mysql_password = "";
$mysql_host = "localhost";
$mysql_table_prefix = "";
$dsn = "mysql:host=".$mysql_host.";dbname=".$database;

try {
$db = new PDO($dsn,$mysql_user,$mysql_password,array(PDO::ATTR_PERSISTENT => true));
} catch (PDOexception $e) {
echo $e->getMessage();
}
$stmt = $db->prepare("SELECT * FROM `".$mysql_table_prefix."settings` WHERE id=1");
if ($stmt) {
$stmt->execute() or die("Execution failed");
$stmt->setFetchMode(PDO::FETCH_NUM);
$row = $stmt->fetch();
$stmt->closeCursor();
echo "Success";
} else {
$error = $stmt->errorInfo();
echo "Statement failed: ".$error[2];
}
If this works, but the first one doesn't, we have it nailed.

SphiderSnow
Posts: 17
Joined: Mon Dec 10, 2018 8:41 pm

Re: Updating Error

Post by SphiderSnow » Tue Dec 11, 2018 10:46 pm

So in running this below (combo of my test and yours) I get: "Got Connection" and "Success". So solution is ...

<?php
$database="XXXXXX";
$mysql_user = "XXXXXX";
$mysql_password = "XXXXXX";
$mysql_host = "localhost";
$mysql_table_prefix = "";
$dsn = "mysql:host=".$mysql_host.";dbname=".$database;

$db = new mysqli("p:".$mysql_host,$mysql_user,$mysql_password,$database);
if ($db->connect_errno) {
trigger_error(
"Database connection failed: ".$db->connect_errno, E_USER_ERROR
);
} else {
echo "Got Connection";
}

try {
$db = new PDO($dsn,$mysql_user,$mysql_password,array(PDO::ATTR_PERSISTENT => true));
} catch (PDOexception $e) {
echo $e->getMessage();
}
$stmt = $db->prepare("SELECT * FROM `".$mysql_table_prefix."settings` WHERE id=1");
if ($stmt) {
$stmt->execute() or die("Execution failed");
$stmt->setFetchMode(PDO::FETCH_NUM);
$row = $stmt->fetch();
$stmt->closeCursor();
echo "Success";
} else {
$error = $stmt->errorInfo();
echo "Statement failed: ".$error[2];
}
?>

User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Tue Dec 11, 2018 11:23 pm

The first half of your combo connects to the database. That is pure mysqli. Quite logical that you get a connection. There is no query using this connection, so just from this I can't tell if that connection is useful.

The second half of your combo also connects to the database, AND the following query succeeds. That is all PDO!

I'd like you to add this to the first half and try it again:
$stmt = $db->prepare("SELECT * FROM `".$mysql_table_prefix."settings` WHERE id=1");
if ($stmt) {
$stmt->execute() or die("Execution failed: ".$stmt->error);
$result = $stmt->get_result();
$row = $result->fetch_array(MYSQLI_NUM);
$stmt->close();
echo "Success";
} else {
echo "Failed to execute statement";
}
This query is mysqli/mysqlnd. The mysqlnd is what allows prepared statements.

I have a STRONG suspicion, that despite the results of earlier phpinfo() results, you host supports PDO but either does not support mysqlnd, or mysqlnd is misconfigured.

Since PDO is definitely supported, I would suggest blowing away the Sphider 2.2 installation and downloading Sphider 2.2.0-PDO. You will NOT need to run install.php or update_rollup.php. Change the settings in database.php and it should load fine. The ONLY issue, and a very minor one at that, will be an incorrect version number reported. That will have ZERO impact until when and if you ever need to update to a newer version. The update will think you don't have PDO when you do. I can provide a script to correct that, if for no other reason than to be consistent.

Now, presuming that the PDO version will load fine, you could might also be able to change the settings to point to the old 1.3.5 database. If your earlier attempts when running the update_rollup.php made the proper changes... Well, the version number would still be off, but you'd have a running installation with all your old data!

SphiderSnow
Posts: 17
Joined: Mon Dec 10, 2018 8:41 pm

Re: Updating Error

Post by SphiderSnow » Tue Dec 11, 2018 11:44 pm

I will give the pdo version a try this evening when I get back to it and let you know what happens

SphiderSnow
Posts: 17
Joined: Mon Dec 10, 2018 8:41 pm

Re: Updating Error

Post by SphiderSnow » Wed Dec 12, 2018 4:06 am

PDO did indeed with just the DB info entered. Going to call it a day on that success but will get to incorporating into my site in the next few days. Thanks for all your effort.

User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Wed Dec 12, 2018 4:18 pm

I am curious... did it connect with the old 1.3.5 db or the newly created one?

If it is the newly created one, the version number should be updated. If you don't? Absolutely no big deal at all until sometime in the future if you ever decided to do an upgrade to the next version (whenever that will be).

If you are using the old db, I'd like to be sure it updated appropriately (and there would still be the version number thing). All easy checks, easy fixes (if any are even needed).

Lastly, there is the language issue. Also pretty easy.

But overall... GREAT! That was good news. I don't know why having a working 'mysqlnd' extension is such a big deal with some hosting companies. My experience tells me it is primarily an issue with shared host clients. IMHO (which can often be wrong), it is about money. "Hey! You want 'mysqlnd"? We offer that on fully hosted plans (few a few dollars more)."

SphiderSnow
Posts: 17
Joined: Mon Dec 10, 2018 8:41 pm

Re: Updating Error

Post by SphiderSnow » Wed Dec 12, 2018 11:10 pm

It is working with the old DB.

I was just looking into the language piece, so whatever your recommended tweaks are for that I guess it is time to try them out.

User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Wed Dec 12, 2018 11:48 pm

Okay. The scenario is that you have Sphider in stalled into a directory name "sphider". In you settings, English is set as the language, so when 'sphider/search.php' is used, the language is English.

Now you want to also present a search option in Spanish. Create a directory named 'es_search'. The name doesn't matter, this is just an example. Now copy 'sphider/search.php' to 'es_search/search.php'.

In the 'es_search' directory, edit search.php. Lines 61-67 show:
$include_dir = "./include";
$template_dir = "./templates";
$common_template_dir = "./common_template";
$tmp_dir ="./tmp";
$settings_dir = "./settings";
$language_dir = "./languages";
$calendar_dir = "./calendar";
Change the paths so that they read:
$include_dir = "../sphider/include";
$template_dir = "../sphider/templates";
$common_template_dir = "../sphider/common_template";
$tmp_dir ="../sphider/tmp";
$settings_dir = "../sphider/settings";
$language_dir = "../sphider/languages";
$calendar_dir = "../sphider/calendar";
Now we need to add a line in three different places. (Actually. since I am betting you only want to use the classic search option and are not interested in RSS or image searches, only the first is critical, but do all three JUST IN CASE you use the others in the future and forgot what you did!)
Lines 199, 284, and 333 each read:
include $settings_dir."/conf.php";
After each of these lines, add:
$language = 'es';

The end result in all three places will be:
include $settings_dir."/conf.php";
$language = 'es';
What you have done is load the configuration settings, then you have OVERRIDDEN the language setting. If you want a third language, say German. create another directory 'de_search', copy search.php there, and make the same changes except it will be "$language = 'de';" instead.

[You may have noticed line 79 - require $settings_dir."/conf.php";. Don't worry about that one. That instance is only looking for which template to use and has nothing to do with language.]

User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Wed Dec 12, 2018 11:57 pm

To set the version number to reflect what you REALLY have, run this from the admin folder:
$settings_dir = "../settings";
require "$settings_dir/database.php";

$db->query(
"UPDATE `".$mysql_table_prefix
."settings` SET version_nr='2.2.0-PDO' WHERE id = 1"
);

User avatar
captquirk
Site Admin
Posts: 126
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Re: Updating Error

Post by captquirk » Thu Dec 13, 2018 12:47 am

I've been "proving" my language solution here locally....
AND I'M HAVING ALL KINDS OF ISSUES!!!
DARN IT!!!

I'll be back.....

Post Reply