Closed cormiodo closed 7 years ago
Need more info such as error call stack to debug
This is the call: require_once 'medoo.php'; $dbstart = new medoo(); $sitoattivo = $dbstart->get("ta_comodo", "valore1", ["suffisso" => "attivo"]);
Fatal error: Call to a member function quote() on a non-object in C:\sutrsy\medoo.php on line 156 Call Stack
1 0.0013 274928 {main}( ) ..\index.php:0 2 0.0213 753832 medoo->get( ) ..\index.php:12 3 0.0213 754416 medoo->select_context( ) ..\medoo.php:669 4 0.0214 755376 medoo->where_clause( ) ..\medoo.php:533 5 0.0215 756824 medoo->data_implode( ) ..\medoo.php:349 6 0.0215 758440 medoo->fn_quote( ) ..\medoo.php:326 7 0.0215 758488 medoo->quote( ) ..\medoo.php:210
I hope that this is what you need. Many thanks.
Please check the code in C:\sutrsy\medoo.php
around line 156.
The 156th line of the official medoo.php file is if ($this->debug_mode)
, not calling function quote().
Maybe some conflict occurred when you upgrading medoo.
You're right! I have deleted some white rows to make it equal to the old one. This is the result using the original:
Fatal error: Call to a member function quote() on a non-object in C:\sutrsy\medoo.php on line 188 Call Stack
1 0.0009 275536 {main}( ) ..\index.php:0 2 0.0135 754480 medoo->get( ) ..\index.php:12 3 0.0135 755064 medoo->select_context( ) ..\medoo.php:829 4 0.0135 756016 medoo->where_clause( ) ..\medoo.php:668 5 0.0136 757464 medoo->data_implode( ) ..\medoo.php:430 6 0.0136 759080 medoo->fn_quote( ) ..\medoo.php:404 7 0.0136 759128 medoo->quote( ) ..\medoo.php:257
PDO not initialized.
Find out the code you create the instance of medoo and make sure you pass the correct settings into constructor.
Dear SyuTingSong, I know what mean the error but I don't understand what I must change. I don't have changed anything on my scripts, I have only updated the medoo.php script. With the previous script my app run without problem then, I think, YOU have changed something and I need know what I must change. Many thanks.
You have to initialize before using it.
@cormiodo We all hope the new version of medoo be compatible with earlier one. However, the medoo is not perfect. Sometimes contributors have to lose some compatibility for new features and bugfixes.
You can check the commit logs and documentations to find out what changed and decide to upgrade or not.
Ok, I find the solution. Before the update, the call for meddo was: $database = new medoo(); After the update: $database = new medoo(['option' => [ PDO::ATTR_CASE => PDO::CASE_NATURAL ]]); Ok, now my question is: because I have a lot of this call on my app and I wan't change all the scripts, how I can change the medoo.php to insert the PDO::ATTR_CASE? Maybe on the row "protected $option = array();" ? I tried to change this, but I don't find the right sintax. Can you help me?
There are several ways to resolve your problem.
The simplest way is just make the $database
as a global variable. So you can only init it in a standalone script with your own options and include this script into others. Nothing change required if your use $database
in global scope. Declare it as global variable if you use it in functions.
The other way is wrap the medoo object with a singleton factory class. If you hate the long static-method-call you can add a function to do this.
class MedooFactory {
private static $db;
public static function getMedoo() {
if (!self::$db instanceof medoo) {
self::$db = new medoo(['option' => PDO::CASE_NATURAL]); // or any config you want
}
return self::$db;
}
}
function database() {
return MedooFactory::getMedoo();
}
Then you can just use database()
to replace the original $database
in your code.
$result = database()->select($table, $columns, $where);
Great. Many thanks.
Seriously , this schuld be in the Documentation. Since im most applications a config.php is used, repeating the DB config in plaintext in every function you like to use si quite wired to me.
@ScrewItFix You don't do that, you make an array of the information, then define a variable that will hold the database object and you put the settings array there. Then you simply pass that variable to other classes/functions. Or instead you could make an object registry which will simplify it even more.
The easiest solution I have found is : to downgrade to the previous release . :-) because , in any case , after the update , my scripts on the server constantly encounter run-time errors. I prefer to stay with the previous release that is performed without any problem. I work as a web application writer and I will not even think to change all my script to use the new release ! Just a tip : I think it's incorrect update a release by changing the way of connecting to the database , forcing users to re-check all the scripts .
Dear all, I have downloaded the new version but I see this error: Fatal error: Call to a member function quote() on a non-object in C:\sutrsy\conmed.php on line 156 I don't have changed anything on my site and reloaded the old version the script run without problem Some help?