yii2 cron giving error of "PDO not found" - php

I am running application well in yii2. I created a command controller /commands/TestController
<?php
namespace app\commands;
use app\models\UserProfile;
use yii\console\Controller;
use app\controllers\AppController;
/**
* Test controller
*/
class TestController extends Controller
{
public function actionIndex()
{
echo "cron service running";
}
public function actionSendBirthdaySms()
{
$userProfile = UserProfile::find()
->where('MONTH(dob) = MONTH(DATE(NOW()))')
->andWhere('DAY(dob) = DAY(NOW()) ')
->with('user')
->asArray()
->all();
foreach($userProfile as $item){
$birthdayMessage = "Happy Birthday " . $item['user']['username'];
//to send sms
$this->_send_cron_sms($item['mobile'], $birthdayMessage);
}
}
I have two functions here. When I call php /home/user/public_html/yii test/index it gives the correct output with command line and cron both.
But when I am running php /home/user/public_html/yii test/send-birthday-sms, it runs OK with command line in ssh environment and I am receiving the SMS. But giving error in cron. Here is what I received in email:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.39
Content-type: text/html
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'PDO' not found'
in /home/user/public_html/vendor/yiisoft/yii2/db/Connection.php:609
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
I also tried query builder but it also did not helped me.

I have solved the issue by adding these two extensions in php.ini file
extension=pdo.dll
extension=pdo_mysql.dll
I already asked the same question in Yii forum

Related

MongoDB insertOne function not found

I'm trying to use MONGODB in my project and I just started using it when it has this problem. I created another directory and ran the files with no problems whatsoever. What is wrong with this? I keep getting Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() error message.
This is my code to the class called Database which is producing the error.
<?php
namespace auth;
include_once dirname(__DIR__) . "/config.php";
class Database
{
public function __construct(
private readonly string $dbname,
){
$this->run();
}
private function run(): void
{
$collection = (new \MongoDB\Client)->{$this->dbname};
$insertOneResult = $collection->insertOne([
'username' => 'admin',
'email' => 'admin#example.com',
'name' => 'Admin User',
]);
printf("Inserted %d document(s)\n", $insertOneResult->getInsertedCount());
var_dump($insertOneResult->getInsertedId());
}
}
and my test.php file just contained some lines of code
include_once "./assets/php/config.php";
$database = new \auth\Database("test->users");
I definitely loaded the class MongoDB and my config.php includes the vendor file of composer's.
This is the error in full.
Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() in C:\xampp\htdocs\PP\assets\php\Classes\Database.php:18
Stack trace:
#0 C:\xampp\htdocs\PP\assets\php\Classes\Database.php(11): auth\Database->run()
#1 C:\xampp\htdocs\PP\test.php(15): auth\Database->__construct('test->users')
#2 {main}
thrown in C:\xampp\htdocs\PP\assets\php\Classes\Database.php on line 18
PHP Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() in C:\xampp\htdocs\PPa\assets\php\Classes\Database.php:18
Stack trace:
#0 C:\xampp\htdocs\PP\assets\php\Classes\Database.php(11): auth\Database->run()
#1 C:\xampp\htdocs\PP\test.php(15): auth\Database->__construct('test->users')
#2 {main}
thrown in C:\xampp\htdocs\PP\assets\php\Classes\Database.php on line 18
Process finished with exit code 255
The config.phpfile that I have included
include_once dirname(__DIR__, 2) . "/vendor/autoload.php";
include_once "autoload.php";
Thanks for any help.
Ah yes answer to my question, I'm just well not thinking properly at the time of writing the code. The `MongoDB\Collection" class accepts two arguments from the user and one internally set. The user provided argument is the database name and collection name. Doing it with (new \MongoDB\Client)->{$this->dbname} is wrong because it provides just the database string and not the collection name.
I resolved this issue by changing how the structure looks of the collection. md is just the alias for MongoDB class as I do not want to type such a long string everytime.
$collection = (new md\Client)->$db->$collection_name;
However, I have no idea how mongoDB uses the db and collection_name as magic constants as I have looked through the entire MongoDB\Client file and found there is no code stating those "magic constants"? I would appreciate if someone has an answer to this.

Delaying jobs in laravel - Call to undefined function curl_init()

so I got this code:
public static function postAllTasks()
{
$allTasks = Tasks::getTasksForToday();
foreach ($allTasks as $task) {
$delay = DB::table('jobs')->count()*20;
PostTasks::dispatch((string)$task->task)->delay($delay);
}
}
It is working fine on my computer just fine, but as soon as it is on the server it returns the error:
Error: Call to undefined function App\Http\Controllers\Traits\curl_init() in /var/www/html/app/Http/Controllers/Traits/TaskTrait.php:89
Stack trace:
#0 /var/www/html/app/Http/Controllers/Traits/TaskTrait.php(224)...
The problem is, that the PHP curl extension is active and visible + when I run exactly the same PHP artisan command, which doesn't use the dispatch/worker but just execute the Job (so it is using curl anyway) right away, everything works.
When I use:
QUEUE_CONNECTION=sync
instead of
QUEUE_CONNECTION=database
It works too, but I need it to use the database in order to calculate the delay between each job.
Laravel Framework 8.55.0
PHP 7.4.3

App Engine - PHP env - 500 error while sending email

I am planning to send GCP cost to stakeholders. I am using app engine to host and send an email.
https://cloud.google.com/solutions/automated-email-cloud-billing-summary
I am using gcloudshell. I am getting below error.
Error: 0.0.0.1:52050 [500]: /?authuser=0&environment_name=default - Uncaught Error: Class 'google\appengine\api\mail\Message' not found in /home/project/billingemails/index.php:39
Stack trace:
#0 {main}
thrown in /home/project/billingemails/index.php on line 39'''
Code:
<?php
namespace Google\Cloud\Samples\Auth;
use Google\Auth\Credentials\GCECredentials;
use google\appengine\api\app_identity\AppIdentityService;
use Google\Cloud\BigQuery\BigQueryClient;
use google\appengine\api\mail\Message;
// Variables holding your values, replace before deploying
$datatable = "projectid.billing_data.gcp_billing_export_v1_000000_000000_000000";
$toemail = "gcpbilling#domain.com";
$fromemail = "your#domain.com";
$message = wordwrap($message, 70, "\r\n");
try {
$mailmsg = new Message();
$mailmsg->setSender($fromemail);
$mailmsg->addTo($toemail);
$mailmsg->setSubject('GCP Billing Summary');
$mailmsg->setTextBody($message);
$mailmsg->send();
printf('<br>---Mail sent successfully!---<br>');
}
catch (InvalidArgumentException $e) {
printf('<br>---Error occurred, could not send email---<br>');
}
?>
It seems by the stack trace - the below part of it - that the class Message is being missed.
Uncaught Error: Class 'google\appengine\api\mail\Message' not found in /home/project/billingemails/index.php:39
For this reason, please, be sure that you have this class well written and in the right folder, so your index.php file can call it correctly and send the email as intended. After this class is in the right place, you should be fine.

Post Web Service in codeigniter using REST Server not working and showing error

I am new for codeigniter and I am using Phil Sturgeon’s REST server for "post" type of web service. althiugh my 'get' type web service is working perfectly. Below is my controller code for post web service.
require(APPPATH.'libraries/REST_Controller.php');
class json extends REST_Controller {
public function __construct() {
parent::__construct();
}
public function data_post() {
$user = array(
'id' => $params['id']
);
$this->response(array('status'=>'success'), 200);
}
}
and i amd using rest add on to check web services working or not but i am getting below error.
Fatal error: Uncaught exception 'Exception' with message 'Format class does not support conversion from "php".' in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php:51 Stack trace: #0 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php(31): Format->__construct('{"id": "restCli...', 'php') #1 /home/magnetic/public_html/touch/order-form/application/libraries/REST_Controller.php(247): Format->factory('{"id": "restCli...', 'php') #2 /home/magnetic/public_html/touch/order-form/application/controllers/json.php(6): REST_Controller->__construct() #3 /home/magnetic/public_html/touch/order-form/system/core/CodeIgniter.php(308): json->__construct() #4 /home/magnetic/public_html/touch/order-form/index.php(202): require_once('/home/magnetic/...') #5 {main} thrown in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php on line 51
http://awesomescreenshot.com/0cd38frz01 is screenshot of rest addon error
Please let me know what else i need to do if anything remaining in my code and please let me know the whole process of using rest server for 'post' web services.
Thanks in advance
In the body of the RESTClient, try sending:
id=restClient%20Test
instead of
{"id": "restCliente Test"}

'Zend_Db_Statement_Exception' with message 'Invalid bind-variable name ':1'

Good day,
Background Info:
Client's hosting server is being upgraded from PHP 5.2 to PHP 5.3. The client's app breaks when tested on PHP 5.3. Specifically the insert and update methods are the ones which are breaking the app. The app coded in Zend Framework v1.7.2.
We have tried simply upgrading the Zend Framework core, however it seems that the previous developers made changes to the core, which causes the app to completely break when the framework has been upgraded.
Problem
The best solution was to add a class called AppModel which extends Zend_Db_Table_Abstract and then simply overwrite the insert and update methods. All models in this app extend the AppModel class. This works fine until checkbox data or radio button data has to be written to the database.
The app now throws the following error:
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with
message 'Invalid bind-variable name ':1'' in ....
NB. Full error message at the bottom
I have been looking for a solution on the internet for days in vain. One of the solutions I found was to change Mysqli to Pdo_Mysql. however it seems that there is no such class in the framework. There is the class Pdo which throws the same error as Mysqli.
Please help!
Please excuse my English. If you need clarification please dont hesitate to contact me. thanks in advance
The following is code sample from the AppModel class:
class AppModel extends Zend_Db_Table_Abstract{
//PHP 5.3 fix
public function insert(array $data) {
//array to carry data for holding data
$ins_data = array();
foreach($data as $table => $value){
$ins_data['tables'][] = $table;
$ins_data['values'][] = mysql_escape_string($value);
}
$db = Zend_Registry::get('db');
$ins_query = ' INSERT INTO '. $this->_name.' ('.implode($ins_data['tables'], ', ').')
VALUES ("'.implode($ins_data['values'], '", "').'")';
$ins_action = new Zend_Db_Statement_Mysqli($db, $ins_query);
$ins_action->execute();
return $db->lastInsertId();
}
}
Complete error message:
Fatal error:
Uncaught exception 'Zend_Db_Statement_Exception'
with message 'Invalid bind-variable name ':1''
in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php:143
Stack trace:
#0 C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php(108): Zend_Db_Statement->_parseParameters(' UPDATE user_te...')
#1 C:\wamp\www\schoolnet\application\AppModel.php(43): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), ' UPDATE user_te...')
#2 C:\wamp\www\schoolnet\application\modules\user\helpers\UserHelper.php(530): AppModel->update(Array, 'user_id = 6')
#3 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(533): user_helpers_UserHelper->teacherUpdate(Array, 6)
#4 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(300): UserController->teacherUpdateDetails(Array, 6)
#5 C:\wamp\www\schoolnet\public_html\Zend\Controller\Action.php(503): UserController->detailseditAction()
#6 C:\wamp\www\schoolnet\public_html\Zend\Controller\Dispatcher\Standard.php(285): Zend_Control in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php on line 143

Categories