error Call to a member function get_results() - php

error:
Call to a member function
get_results() on null in C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php:9 Stack trace: #0 {main} thrown in C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php on line
the code
global $wpdb;
$query = $wpdb->get_results('SELECT * FROM test');
The folder myplugin contains the following two files,
index.php
viwe.php
For file viwe.php, the code is not working and fails with,
error
Call to a member function
get_results() on null in C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php:9 Stack trace: #0 {main} thrown in C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php on line
But the index.php is working.

Add these two lines at the top.
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-config.php');
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-load.php');
You need to include those files so the function get_results() becomes available to be called.

Related

Base path in php 7

I am using
php 7.4.3
composer v4.1.4
I have this error
Fatal error: Uncaught Error: Call to undefined method Dotenv\Dotenv::createImmutable() in C:\xampp\htdocs\ecommerce\app\config\_env.php:9
Stack trace:
#0 C:\xampp\htdocs\ecommerce\bootstrap\init.php(8): require_once()
#1 C:\xampp\htdocs\ecommerce\public\index.php(3): require_once('C:\\xampp\\htdocs...')
#2 {main} thrown in C:\xampp\htdocs\ecommerce\app\config\_env.php on line 9
Define base path
_env.php ------------> any other method of defining realpath?
<?php
define('BASE_PATH', realpath(__DIR__.'/../../'));
require_once __DIR__.'/../../vendor/autoload.php';
$dotEnv = Dotenv\Dotenv::createImmutable(BASE_PATH);
$dotEnv->load();
index.php
<?php
require_once __DIR__ . '/../bootstrap/init.php';
$app_name = getenv('APP_NAME');
echo $app_name;

Class 'Dropbox\AppInfo' not found - PHP

My code, script start.php in app folder:
require __DIR__ . '../../dropbox-php-sdk-master/vendor/autoload.php';
session_start();
$_SESSION['user_id'] = 1;
$dropboxKey = '';
$dropboxSecret = '';
$appName = '';
$appInfo = new Dropbox\AppInfo($dropboxKey,$dropboxSecret);
My folder structure:
1.app
1.1. start.php
2.dropbox-php-sdk-master
2.1.vendor
2.1.1. autoload.php
3.index.php (calls function start.php)
And when I call the index.php i recive this erro:
Fatal error: Uncaught Error: Class 'Dropbox\AppInfo' not found in C:\xampp\htdocs\tutorials\dropboxapi\app\start.php:12 Stack trace: #0 C:\xampp\htdocs\tutorials\dropboxapi\index.php(3): require() #1 {main} thrown in C:\xampp\htdocs\tutorials\dropboxapi\app\start.php on line 12
I follow some tutorials on the internet and they all have the same structure, what Im doing bad?

Share PHP Rivescript object into $_SESSION

I have a issue trying to save an object into session.
From my index.php I create the object and store it into session:
include_once __DIR__.'/vendor/autoload.php';
use Axiom\Rivescript\Rivescript;
$test = new Rivescript();
$test->load(realpath(__KNOWLEDGE__));
session_start();
if (isset($_SESSION['ENGINE'])){
unset($_SESSION['ENGINE']);
}
$_SESSION['ENGINE'] = $test;
in another php page I recall the session to get te object:
session_start();
if (!isset($_SESSION['ENGINE'] )){
// error
}else{
$test = $_SESSION['ENGINE'];
$txt = $test->reply($input,$client_id);
}
This page is called by AJAX.
and I get this error:
Notice: Trying to get property 'memory' of non-object in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php on line 64
Fatal error: Uncaught Error: Call to a member function substitute() on null in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php:64 Stack trace: #0 /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php(33): Axiom\Rivescript\Cortex\Input->cleanOriginalSource() #1 /var/www/html/vendor/axiom/rivescript/src/Rivescript.php(34): Axiom\Rivescript\Cortex\Input->__construct('ciao', '5e5fe0688782a') #2 /var/www/html/include/bot.php(24): Axiom\Rivescript\Rivescript->reply('ciao', '5e5fe0688782a') #3 {main} thrown in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php on line 64
Any help ??

phantomJs permission denied

Have a question and I have the feeling it should not be to hard to solve but I'm not really familiar with Phantom Js.
$this->phantomProcess($path)->setTimeout(10)->mustRun();
This line results in the following error:
protected function captureImage($view)
{
$path = $this->writeFile($view);
$this->phantomProcess($path)->setTimeout(10)->mustRun();
return $path;
}
protected function writeFile($view)
{
file_put_contents($path = 'storage/' . md5(uniqid()) . '.pdf' , $view);
return $path;
}
protected function phantomProcess($path)
{
return new Process('bin/phantomjs capture.js ' . $path);
}
I'm running the following line:
Fatal error: Uncaught exception 'Symfony\Component\Process\Exception\ProcessFailedException' with message 'The command "bin/phantomjs capture.js storage/7c5b791a0c1f131aac5c5ca272a1c891.pdf" failed. Exit Code: 126(Invoked command cannot execute) Working directory: /Applications/XAMPP/xamppfiles/htdocs/pdf Output: ================ Error Output: ================ sh: bin/phantomjs: cannot execute binary file ' in /Applications/XAMPP/xamppfiles/htdocs/pdf/vendor/symfony/process/Process.php:239 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/pdf/app/Codecourse/Capture/Capture.php(45): Symfony\Component\Process\Process->mustRun() #1 /Applications/XAMPP/xamppfiles/htdocs/pdf/app/Codecourse/Capture/Capture.php(24): Codecourse\Capture\Capture->captureImage('<!DOCTYPE html>...') #2 /Applications/XAMPP/xamppfiles/htdocs/pdf/index.php(17): Codecourse\Capture\Capture->load('invoice.php', Array) #3 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/pdf/vendor/symfony/process/Process.php on line 239
Anybody who can help me out?
Really appreciated,

Autoload error in php

I am trying autoload function in php. The files are all in the same directory.
I have a file called aviation.php with the following code:
class Avaitor{
public function __construct(){
echo "Fly high<br>";
}
}
Then in my autoloader file I am trying to do this:
function __autoload($fileName){
if(file_exists($fileName . ".php"))
require_once $fileName . ".php";
}
//require_once "aviatior.php";
$pilot = new Avaitor();
But I am getting this error:
Fatal error: Uncaught Error: Class 'Avaitor' not found in
/Applications/MAMP/htdocs/php_oop/autoload.php:22 Stack trace: #0
{main} thrown in /Applications/MAMP/htdocs/php_oop/autoload.php on
line 22
Just to test that require_once does find my aviator.php I tried it out and then commented it out.
What am I doing wrong here?

Categories