mysql connect doesn't work on command line - php

If I create php file and open it in browser with following content:
<?php
var_dump(function_exists("mysqli_connect"));
I receive:
bool(true)
but when I do it from ssh command line
php -r 'var_dump(function_exists("mysqli_connect"));'
I receive:
bool(false)
Why is that? I can use mysqli_connect / mysql_connect while operating my websites from browser, but can't on ssh.
I wanted to update my phpbb 3.0 to phpbb 3.1 via the command line:
php ./bin/phpbbcli.php db:migrate --safe-mode
but as you see, I can't. The output is:
PHP Fatal error: SQL ERROR [ mysqli ]<br /><br />mysqli_connect function does not exist, is mysqli extension installed? []<br /><br />An sql error occurred while fetching this page. Please contact an administrator if this problem persists. in /zzzzzzzzz/phpbb/db/driver/driver.php on line 855
Of course my phpbb 3.0 board works well on mysqli. Could somebody help me?

I don't know if you solved this or not, but try putting the full path to the php file like so
/Applications/MAMP/bin/php/php5.5.38/bin/php bin/phpbbcli.php db:migrate --safe-mode
as you might be executing a php version different from the one you have configured with mysql
Hope this helps someone

Related

Cannot connect to MySQL Database with MDB2 (Error not Found)

In first point. I am absolutely a noob in PHP and PEAR. For exercising I have worked with PHP, Pear and Mondial DB of Oracle offline, but now I wanted to connect to my Database on 1and1.com.
Following I have tried:
$dsn = 'mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx'; //Have it tried with password too and many other variations
$sql = "SELECT * FROM Vereine";
$db = MDB2_Util::connect($dsn);
If I upload this file on my webserver and when I try to call this page, I get an error.
Fehler beim Verbindungsaufbau mit [mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx] : MDB2 Error: not found
The error Message:
"Fehler beim Verbindungsaubau" is an own deinied Message in MDB2_Util.
If I try to connect with MDB2::connect, then the Message calls only:
MDB2 Error: not found
What can be the Error? Why it doesnt show the real Error or a helpful hint. Can I debug? If yes, how?
Best Regards Benny
This can occur even if you have installed an MDB2 driver, but PHP can't find or can't read it.
As a practical example, I experienced this problem on a system on which the UMASK value had been changed from 022 to 027. Even though the MDB2 driver had been installed (with root privileges), the user under whom php-fpm was running lacked access to the library's files.

Failed opening required database.inc (attempting to use drupal)

I am trying to setup a drupal web server with FreeBSD.
When I try to access the drupal index i am greeted with:
Fatal error: require_once(): Failed opening required
'/usr/local/www/apache24/data/drupal/includes/database/sqlite/database.inc'
(include_path='.:/usr/local/share/pear') in
/usr/local/www/apache24/data/drupal/includes/database/database.inc on
line 1685
I am new to freeBSD but i tried setting chmod 667 to the:
sqlite/database.inc
database/database.inc
sqlite
database
Also, i do not understand why it is looking for /usr/local/share/pearas there is no such directory.
I am using MySQL55, PHP5, Drupal-7, and Apache.
I think this might be related but when i access the install.php i get:
Undefined index: distribution_name in drupal_install_profile_distribution_name() (line 201 of /usr/local/www/apache24/data/drupal/includes/install.inc).
did you use drush?
That looks as if you already installed drupal, or at least drupal thinks so. and also with the wrong database settings. normally, you will be prompted to enter them in the web interface, but you also can enter them directly in the settings php. Propably you should just move the old settings.php and run install.php in your browser and enter the database details anew.
drupal_install_profile_distribution_name can be changed in the database under system->standard_profile and variable->install_profiles directly or using drush (www.drush.ws) with
vset install_profile standard
or any other install profile you used.
Anyways, the install script asks for that as well.
hope, this was your problem.

Phalcon Mongo Class not found error

I attempting to setup Phalcon PHP using a Mongo database connection. I have configured my bootstrap (index.php) file using the following:
// Mongo database connection
$di->set('mongo', function(){
$mongo = new Mongo();
return $mongo->selectDb("phalcon");
}, true);
// Collection Manager
$di->set('collectionManager', function(){
return new \Phalcon\Mvc\Collection\Manager();
});
Whenever I attempt execute an insert fucntion in using this connection, I receive a 500 Internal server error. Now, I have checked my apache server error logs and it states "PHP Fatal error: Class 'Mongo' not found in /var/www/phalcon-mongo/public/index.php on line 17".
I don't know why this request is not processing, according to the documentation given from Phalcon, the connection to mongo DB is setup up as I have displayed above.
If anyone has any advice, please let me know.
i think it's because your installation of Mongo is not valid.
try printing phpinfo() and check if mongo is loaded at all, if not - install it, add to ini files (if you use cli, don't forget to add to cli ini too) and reach the moment, when mongo is fully loaded.
try mongo w/o phalcon. any simple connection/insertation. you can see here: Fatal Error - 'Mongo' class not found that there are problems with apache module version for some people. Try reinstalling different mongo version.
if you can print this out:
echo Phalcon\Version::get();
there should be no problems with phalcon instalation
to validate mongo installation, try any of examples from php.net:
http://www.php.net/manual/en/mongo.tutorial.php
if both installations are valid, then there are problems with your custom code, but before doing anything you have to validate both installations.

Codeigniter Command line error - PHP Fatal error: Class 'CI_Controller' not found

After following the user guide instructions found here: http://ellislab.com/codeigniter/user-guide/general/cli.html I'm unable to run the test script via command line.
My controller located at /var/www/mysite/application/controllers/
class Tools extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
In my browser I can access
http://mysite/tools/message/ben
And the function correctly outputs "Hello ben"
From terminal I should be able to run:
$ php index.php tools message "Ben"
My terminal should print: "Hello Ben"
However I get the following error:
PHP Fatal error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php on line 233
My server is pretty standard; ubuntu LAMP. Codeigniter is pretty standard too and I have no problem running non CI scripts via command line
My PHP binary is only located in /usr/bin/php <-- This post suggests an issue running CI directly from usr/bin/php, however I'm not operating a shared PHP service, and I don't see why this would make a difference to how PHP executes a CI script.
Any help or just an indication on how to debug this would be greatly appreciated.
Thanks in advance.
Solved! (partly) the issue was CodeIgniters error logging.
In application/config/config.php, I modified the following config property:
$config['log_threshold'] = 0;
This disables logging, and allows $ php index.php to execute.
If anyone can explain why CI only shows this error on CLI PHP - might help anyone else who has this issue and needs it resolved with error logging on.
To solve error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php then check the database details like hostname, username, password and database.
To Mijahn:
I had this same problem, and after about two hours of tracing through code to figure out the problem, it seems that there is some sort of conflict with loading the CI_Controller when utilizing the native PHP load_class function.
I worked around this issue by making the following changes to the Common.php file (hack, I know).
//$_log =& load_class('Log');
require_once('system/libraries/Log.php');
$_log = new CI_Log();
My logs then where created exactly like I wanted. Hope this hack helps.
This site says to run codeigniter from the command line, one must set the $_SERVER['PATH_INFO'] variable.
$_SERVER['PATH_INFO'] is usually supplied by php when a web request is made. However, since we are calling this script from the command line, we need to emulate this small part of the environment as a web request.
The answer provided in this Stack Overflow post worked for me.
Within system/core/CodeIgniter.php, on around line 75, change:
set_error_handler('_exception_handler');
to...
set_exception_handler('_exception_handler');
Other users have reported that this gave them a better backtrace with which to debug the underlying issue, but for me, this actually removed the problem altogether.

Php - Ingres, fresh install : How to debug?

I just finished to install Ingres on my server(only the client part, to connect to an existing ingres server), I just added the php_ingres module.
Now php recognize my module, so I tried to connect my self to several existing servers, but I always a
Unable to connect to database (Hostname here)
But with this I can't find what is wrong?? ingres error? Php driver? Credentials? ...?
What can I do to isolate these problem?
Most likely it's a user credentials issue. To see the actual error message use the following code:
$connection = ingres_connect(.....);
if (!is_resource($connection))
{
trigger_error(ingres_errno()." - ". ingres_error(),E_USER_ERROR);
}
You might also want to take a look at http://community.ingres.com/wiki/Ingres_with_Apache_on_Debian_Etch which outlines the setup steps for Ingres, PHP, Apache and Debian/Ubuntu.

Categories