Can you use odbc_connect() on openshift? - odbc

In openshift this code
<?php
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
~
returns
PHP Fatal error: Call to undefined function odbc_connect()
Can you use odbc_connect() on openshift?

I do not believe that OpenShift includes the iODBC driver, you can check for sure by creating a php page with the following contents and then checking it for iODBC support
<?php
phpinfo();
You should add your request to have iODBC support at https://ideas.openshift.com and get people to vote on it.

Related

Unable to send mail (Wordpress and AWS)

Context:
I am using Amazon Web Services to build and run a Wordpress site.
Issue:
The problem I have is with sending e-mails from the site. I also installed the plugin "Post SMTP". The error message I am getting is "Email could not be resent. Error: Unable to send mail. ".
What I tried so far:
I reached out to AWS and they wrote me to use Amazon SES service. I have created and configured an identity on SES. The issue is still there.
I don't know where to look anymore. Can anyone help who faced same or similar issues?
Thanks!
Check if the phpmail function is working properly. You can use the following code to check it.
<?PHP
$sender = 'someone#somedomain.tld';
$recipient = 'you#yourdomain.tld';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
Create a php test file using a text editor and save it e.g. as test.php
Change the $sender and $recipient in the code.
Upload the php file to your webserver.
Open the uploaded php file in your browser to execute the php script.
The output show either "Message accepted" or "Error: Message not accepted".
If it's showing "Error: Message not accepted"Tell your provider that the standard php "mail()" function returns FALSE.
It's recommended to include the used php test script to show your provider, that the problem is not caused by the php script used.

PDO Exception: An exception occurred in driver: could not find driver for mysql

I know it is frequently asked question. But I reviewed and read all of it. Unfortunately I could not find a correct answer for my problem. I am using symfony. I followed the instruction and tutorial on https://symfony.com/doc/current/doctrine.html. all steps went perfectly. I run the following commands in terminal without any problem:
composer require symfony/orm-pack
composer require --dev symfony/maker-bundle
php bin/console doctrine:database:create
php bin/console make:entity
php bin/console make:migration
php bin/console doctrine:migrations:migrate
php bin/console make:controller ProductController
with the above commands I could create a database, ProductEntity, a table for Product
Till this point I suppose that the connection to my database runs perfectly.
Then in ProductController I used the Code on the symfony website:
// src/Controller/ProductController.php
namespace App\Controller;
// ...
use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
class ProductController extends AbstractController
{
/**
* #Route("/product", name="create_product")
*/
public function createProduct(): Response
{
// you can fetch the EntityManager via $this->getDoctrine()
// or you can add an argument to the action: createProduct(EntityManagerInterface $entityManager)
$entityManager = $this->getDoctrine()->getManager();
$product = new Product();
$product->setName('Keyboard');
$product->setPrice(1999);
$product->setDescription('Ergonomic and stylish!');
// tell Doctrine you want to (eventually) save the Product (no queries yet)
$entityManager->persist($product);
// actually executes the queries (i.e. the INSERT query)
$entityManager->flush();
return new Response('Saved new product with id '.$product->getId());
}
}
It gives Error: Driver not found like in the picture
I have checked database url in env, it works without problem (I created a database and product table through it). I checked phpinfo and pdo_mysql is enabled without problem.
I have tested database connection with fixature following the instruction here https://symfony.com/doc/current/testing/database.html and was successful without problem
Can you please help me?
Thanks to guillaumesmo, I used symfony php -m. Here I saw the error unable to load pdo_mysql library. I remembered, that I have 2 PHP Versions installed on my system.
I updated the PHP Version to PHP 7.4.1 and deleted the older versions. It works perfectly. I didn't understand why could I connect and update my database via Terminal and Fixature but not with EntityManagerInterface. Anyhow I works now

Undefines function get_field() on PLESK Schedulation Tasks

I'm trying to create a schedule script php from PLESK but i have a problem when i've use get_field() function from ACF.
Plesk retriew the error:
" PHP Fatal error: Uncaught Error: Call to undefined function get_field()..... "
I have the same problem with all function called from Wordpress.
The code inside the PHP script is:
$my_var = get_field('indirizzo_ip','options');
echo $my_var;
Can someone help me?
Thanks
Include these files at the top of your script and you`ll have all the WordPress functions available:
define('WP_USE_THEMES', false);
require('/path/to/your/httpdocs/wp-blog-header.php');
require('/path/to/your/httpdocs/wp-admin/includes/admin.php');
Regards Tom

Symfony 2.4: An error occurred while loading the web debug toolbar (404: Not Found)

I just downloaded a fresh copy of Symfony 2.4.1 on a Debian 7.3.
The URL /Symfony/web/config.php opens correctly, but when I proceed to Configure, I get:
The requested URL /Symfony/web/app_dev.php/_configurator/ was not found on this server.
If I Bypass configuration and open /Symfony/web/app_dev.php
the page displays, but an error pops up saying:
An error occurred while loading the web debug toolbar (404: Not Found)
Do you want to open the profiler?
If I accept, I get:
The requested URL /Symfony/web/app_dev.php/_profiler/54a8bf was not found on this server.
In other questions (e.g. Symfony 2: 404 Not Found Error when tryes to open /app_dev.php) people suggest to fiddle with the .htaccess file.
I even tried removing it, but it had no effect.
The apache log file shows:
File does not exist: /var/www/Symfony/web/app_dev.php/_wdt/54a8bf, referer: http://wwwtest.di.unipi.it/Symfony/web/app_dev.php
File does not exist: /var/www/Symfony/web/app_dev.php/_profiler/54a8bf
So it looks like routing to any inner URL fails, despite the fact that the correct routing seems to be in place:
> app/console router:debug
[router] Current routes
Name Method Scheme Host Path
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_configurator_home ANY ANY ANY /_configurator/
...
I have changed memory_limit in /etc/php5/fpm/php.ini to 512Mb and debug toolbar started to work.
Found solution for me here
The solution for me was to update my app_dev.php file to resemble the one in the Symfony2 repo
Notice the Debug class being used. This wasn't used in older versions of symfony. I updated this file and the javascript alert appears to be gone.
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
/*
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Is the following present in web/app_dev.php? The line below fixed it for me.
$kernel->terminate($request, $response);
Apache directive DirectoryIndex app.php does the tricks for me.
I put it in apache vhost conf with AllowOverride None to prevent override by .htacces.
Hope this help.

How to set the environment in a Symfony2 console command

Hopefully a simple question - how does one specify which environment to use when running a console command in Symfony2. I've created a few commands, however I would like to run them in the context of my 'staging' environment when on my staging server and my 'prod' environment when on my production server (the different environments define different database connections). How do I configure and pass this information to my console command?
You have two options that will help you out. You can specify the environment that the console will run in with the --env flag, and use --no-debug to disable debug mode.
php app/console --env=staging your:console:command or php app/console --env=prod your:console:command should do what you're looking for (the console runs in the dev environment with debug on by default).
You can look at the code of the app/console file for more info.
You can also use the SYMFONY_ENV environment variable to set a default environment distinct to 'dev' (e.g. export SYMFONY_ENV=prod in ~/.bash_profile)
To answer the question #croca had, to expand on what #Francesc Rosàs posted, and as #Problematic suggested.
If you look in app/console you should see $env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
All this does is checks the input arguments passed to the console for --env or -e, checks the default value from getenv('SYMFONY_ENV'), or sets it to dev if neither are supplied.
It is then passed to $kernel = new AppKernel($env, $debug);
You could essentially either make changes directly to app/console to achieve your application's specific functionality or copy app/console to a separate file such as app/exec, then process the $env variable how you prefer to determine the desired environment.
Simple Example: app/exec
#!/usr/bin/env php
<?php
/**
* disabled debug mode,
* set environment based on requesting address being local
* otherwise the server's IP address
* be sure to perform at least chmod(750) on the file to ensure it is executable
* otherwise it must be prefixed with your php executable
*/
set_time_limit(0);
require_once __DIR__.'/bootstrap.php.cache';
require_once __DIR__.'/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
$input = new ArgvInput();
$env = ($_SERVER['REMOTE_ADDR'] === '127.0.0.1' || $_SERVER['REMOTE_ADDR'] === '::1' ? 'dev' :
($_SERVER['SERVER_ADDR'] === '192.168.2.1' ? 'test' : 'prod')
);
$kernel = new AppKernel($env, false);
$application = new Application($kernel);
$application->run($input);
Then call php app/exec namespace:command arguments --flags
Additionally you could process your own application instead of using the app/console AppKernel - instructions from Symfony can be found here: http://symfony.com/doc/current/components/console/introduction.html
The official documentation says:
By default, console commands run in the dev environment and you may want to change this for some commands.
So, as #Problematic suggest, you can specify the environment for your command using the flag "--env=your_env" or its shortcut "-e your_env".
I wonder whether it is possible to force the default environment for a command. I mean, without having to use the flags. Any idea?
There is another variant, not so convenient though, but works also with composer
SYMFONY_ENV=prod app/console cache:clear
Maybe you could look at the implementation of the cache:clear command. This may give you some clues on how to choose the environment from a command.
app/console help cache:clear

Resources