run php script from command line
Hey all,
I have a PHP script that I want to run from the command line. I am connecting to a mysql database. When i run from the web browser, it connects and runs all queries just fine. When I run from the command line I get the following error: Code:
Fatal error: Call to undefined function mysql_connect() in /path/to/file.php Thanks all!! |
Quote:
|
Yes, same file, and yes I am including the connection strings from a separate file:
Code:
include_once "../dbconnect.php"; |
Quote:
|
TB0ne,
Thanks for the try, but that did not work. I copied dbconnect.php into the same directory as my script, and changed the include to the relative path (of the local file). I also tried placing the connection string code in my file and that also did not work. Side note: Code:
[root@web1 common]$php -m |
Quote:
Compare the contents with /etc/php4/apache/conf.d/mysql.ini. Also check if /etc/php4/cli/php.ini does not prohibit the loading of mysql. I know I am pointing you to the php4 directories. I AM running php5, so I hope the directory name is a leftover of the old times. I also see that I have edited php.ini at least once, perhaps to correct the same problem as you have. Even if your system is different, the clue might be the different config files. jlinkels |
jlinkels,
Interesting information. I didnt know running from browser and CLI use different configuration files. However, I do not have a /etc/php4 OR /etc/php5 directory. Code:
$ php -v Code:
phpinfo(); # run from browser I remember having trouble when I setup php with mysql. PHP 5 functions do not work via web browser, so I know I am running 4.3.9. I tried search for php, php4, php5 directories, and found nothing. Any ideas? |
I just looked it up on a system where I installed PHP5 without upgrading from a previous version. There the directory name is /etc/php5/...
If this is your FC system, I am lost about where FC stores its config files. Unfortunately FC and Debian have some different ideas as where to store configurations. But if it is your Ubuntu system, I am surprised if there is not /etc/phpx directory. Anyway, I also expect a conf.d somewhere containing a file mysql.ini which contains the name of the loadable module, which is mysql.so. There are many more conf.d on your system and some more mysql.ini. Use your common sense to check which are applicable. Also, did you try to find the files with 'locate'? Did you do an updatedb?. Did you search with 'find' and use the proper globbing? '"*php*"' or so? (without the SINGLE quotes, but including the double quotes) jlinkels |
Hi
phpinfo() shows the .ini files being read. Look at the output of: php -r "phpinfo();" |grep .ini |
Guttorm,
Thanks. Found the following: Code:
[root@web1 josh]$php -r "phpinfo();" | grep .ini Thanks for all the help guys! |
It seems you have two different versions of PHP installed, and since you compiled and installed it on "/usr/local/", the easiest thing is probably to compile it again with mysql support.
PHP used to include the mysql client library before, but they dropped it, since it's usually handled better by the distros. So if you had problems installing mysql support in php5, it's probably because you don't have it installed. Your distro should have a package called "libmysqlclient15-dev" or similar. Also, when you run php from the command line, there are no services involved, so there is nothing to restart. php -r "phpinfo();" |less This will show the configuration of the command line version, and until it shows the mysql module, the mysql functions will not work. |
Thanks very much for the help!!!
|
All times are GMT -5. The time now is 02:19 PM. |