PHP with MSSQL Connection not working in command Line (cmd) - php

I want to run my php Script from the command line but it always throws an error.
If i run the same Script in a Browser everything works fine. There seems to be a problem with the paths. But the .dll files are in the correct folder. I also tried "Run as Administrator" but the error still exists.
Browser
Console

The reason is that PHP CLI uses different phpini config. you need to set a custom config and load it with new settings:
use this article to create a custom .ini and use it with CLI

You need to use static paths for your includes like
C:\xampp\htdocs\test.php

Related

Can't access PHP command in Command Line

I have a problem in accessing the php command using command line.
I also created a PATH in my environment variables.
The PATH is like this
C:\wamp\bin\php\php5.5.12
Now the console output is this
C:\Users\Web4>php
'php' is not recognized as an internal or external command,
operable program or batch file.
I also restarted the PC and the command console still same effect. I also created a batch for this still same effect too.
SET PATH=%PATH%;C:\wamp\bin\php\php5.5.12
Is there some configuration other than this? I am using wampserver.
If you run echo %PATH% and it does not include the path to WAMP, then the problem is simply that you haven't set it properly in your environmental variables.
The setting is located here:
http://i.imgur.com/fy5LvRD.png
Edit the System Variables "Path" field and prepend your path to WAMP (obviously make sure you have the exact path to the folder where php.exe is located). Then click OK until all the settings dialogs are closed.
Once you change the path, you will need to close your CMD window and open a new one. The path changes don't take effect on any open CMD windows.

Command 'php' not recognized but it is registered in Windows PATH

I have "C:\Ampps\php" setup in the PATH string on my Windows server but when I type 'php' on the PHPStorm terminal I'm always given 'php' is not recognized as an internal or external command, operable program or batch file.
Is this a bug with PHPStorm 7.1.3? It works from the command line if I open a new Command Prompt window externally.
For any new readers facing such problem in PhpStrom just set path directly from PhpStrom terminal
set path=%path%;c:/xammps/PHP
Not recommended to use PHP from xammps or other such programs since it will be your working PHP directory and if it gets deleted then you have to perform another task to handle it or some errors might pop up in windows just install a fresh version of PHP lots of tutorials are out there for Windows.
But nevertheless to use PHP in PhpStrom Terminal from xammps just run that command it will set the path that PhpStrom can find.
I had the same problem. I have "C:\__OPENSERVER__\modules\php\PHP-7.2-x64" setup in the PATH.
To solve it I added in PhpStrom terminal and executed:
set path=%path%;C:\__OPENSERVER__\modules\php\PHP-7.2-x64
open setting in file menu
find tools tab in this window
click on terminal
in project setting click on environment variable
add php path (for example "C:/xampp/php") to this and save
restart phpstorm

PHP command line fails with no error on full path

Basically it's this
>php /full/path/to/php/file.php
Fails with no output, warning, error anywhere in any log. Seems like it runs fine, but it actually does not run. However, changing working directory to /full/path/to/file/php
> php file.php
Works as expected.
What is special about this php script is that it:
reads files from an NFS mount
parses contents
loads file contents into a local MySQL table
renames files it has successfully loaded.
Operating system is CentOS 6.
Based on your edit, in your script, you should change to the correct directory. You can do that using using chdir:
chdir('/full/path/to/php/');
Now php is probably looking for the symlink in the wrong place.
You can use getcwd() to see in which directory you are.

PHP exec('git') failing

Specifically, I'm trying to get ViewGit working on a PHP/Apache/Windows installation.
It seems that PHP is unable to run exec('git');.
exec('whoami'); works just fine, so it isn't a problem with exec() being disabled.
Apache is running under it's own user account- if I log in as this user and attempt to run git on the command line I get the expected results. The account also has full permissions to do everything with the /Program Files/Git folder.
If I run exec('git'); on my local machine it works fine, but just won't work on the server.
Any ideas?
When you type 'git' in command-line on Windows, it opens git.cmd. In typical msysgit installation on Windows, git.cmd is in PATH, but git.exe may not be!
So, you can try one of below:
Create a git.bat in Windows folder with following contents:
C:\Program Files (x86)\Git\bin\git.exe (check path)
Add git's bin directory also in Windows PATH. (You can do so by editing system environmental variables)
I've managed to fix this by upgrading from PHP 5.2 to PHP 5.4. Not sure what the issue was, but that has resolved it.

MySQL functions not working when PHP script is called from exec()

I have a PHP script I execute in the background from an exec call. Everything works except for the MySQL functions (they don't exist). If I call the script directly from the browser it works fine. What's happening here? Any ideas?
Thank you for your time
Either your command line php was not compiled with php, or php.ini for your command line php does not have the mysql driver module loaded. You'll need to reconfigure and/or rebuild your php installation.
Probably, php_mysql.so is not enabled in your main php.ini but is enabled in an additional ini file added to Apache with PHPIniDir.
Compare output of phpinfo() called from the command line and from a web script. You should see the difference between the ini files and directories used.

Categories