how to enable mysql on php5.... apache 2.2 on windows - mysql

So I've uncommented the the *extension=php_mysql.dll* line in the php.ini file and I've also filled in the *extension_dir* and *doc_root* but everytime I try to run a php file with the following code:
<?php
mysql_connect("localhost", "root", "admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
I get the following error:
"Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\vhosts\guestbook\extract.php on line 3"
Does anyone know how to fix this?

Your PHP is enabled - that's what's throwing the error you are seeing.
The problem is with the PHP config. The mysql extension is not loaded.
I've uncommented the the *extension=php_mysql.dll* line
And have you checked the file exists in the specified extension dir and is readable by the webserver?
Have you checked that this is the php.ini file your webserver is using? (try running a script with just a call to phpinfo() in it).

It sounds like you have either not restarted Apache for php.ini changes to take effect, or that you do not have the PHP /ext path in your system PATH variable (or it's set wrong in php.ini).
Consider using a pre-configured and fully set up WAMP package such as:
xampp (free) -
WampDeveloper Pro (commercial) -
WampServer (free)

Related

Moodle: Installation failed - Coding Error Detected

I have tried to install Moodle 3.5.1 on my development server (Apache 2.4.29 and MySQL v.5.7).
The installation process went smoothly: The MySQL database has been set up, all required PHP packages are installed, the system has been successfully installed, all file permissions are correct.
After the installation I only get the following error:
"Coding error detected, it must be fixed by a programmer: PHP catchable fatal error"
There are no further error messages. There are no error messages in Apache Error log or PHP log files. In the PHP ini file the display of error messages is activated.
So I can not figure out what did not work or how to fix it.
Put error_reporting(E_ALL); and ini_set('display_errors', 1); in the beggining of the script you see problem in for more debug info
Moodle 3.5 requires PHP 7
https://docs.moodle.org/35/en/PHP
Could that be your problem?

Fatal error: Uncaught Error: Call to undefined function mysql_connect()

I am not sure why this isn't working. Here is the code it is referencing.
function db_connection($query) {
mysql_connect('127.0.0.1', 'runner_db_user', 'runner_db_password')
OR die(fail('Could not connect to database.'));
mysql_select_db('ntc_race_info');
return mysql_query($query);
Make sure your installation of PHP has been compiled with mysql support. Run a phpinfo() to see if the php_mysql extension module is loaded. Create a test web page containing
<?php
phpinfo();
?>
then run it,If you don't see page for MySQL, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in
or use mysqli_connect() instead of mysql_connect()
$con = mysqli_connect("127.0.0.1","runner_db_user","runner_db_password","ntc_race_info");

How can I check if a Perl module (DBD::mysql) is properly installed?

I am using XAMPP on Mac OS X Yosemite, and I am trying to communicate with my MySQL database using Perl.
This requires two things: (1) DBI and (2) the mysql driver module, DBD::mysql.
I ran into a lot of trouble installing the DBD::mysql portion. However, after following some instructions online, it now looks like DBD::mysql is installed, but I am skeptical that it has correctly.
In Terminal, when I load up cpan and then type "install DBD::mysql", it responds, "DBD::mysql is up to date (4.032)".
From the looks of it, then, it is installed. However, I am worried that what I've installed is enough for it to say, "Hey, I am installed!", but not enough for it to actually be functional, which would be why I'm having errors show up when I try to connect to my database with Perl:
install_driver(mysql) failed: Can't load '/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
Reason: image not found at /System/Library/Perl/5.18/darwin-thread-multi-2level/DynaLoader.pm line 194.
at (eval 6) line 3.
Compilation failed in require at (eval 6) line 3.
Perhaps a required shared library or dll isn't installed where expected
at login.pl line 9.
Relevant Perl code snippet:
my $dbh = DBI->connect(
"dbi:mysql:dbname=TEST",
"root",
"",
{ RaiseError => 1 },
) or die $DBI::errstr;
I am trying to troubleshoot whether this is a problem with my installation of DBD::mysql, or if it is my Perl code.
How can I verify whether my installation of DBD::mysql is all good? Better yet, how can I stop getting this error?
Thank you.
You could wrap the connect() call into an eval block to catch this error, however you don't have many options left if it crashes, probably just to try and produce a more user-friendly error messsage and then die anyway.
As for why you are getting the error, try checking where libmysqlclient.18.dylib lives on your system. It seems like it was somewhere where it could be found during compilation of the DBD::mysql driver but not during your script's runtime. Assuming it hasn't been accidentially uninstalled, adding its directory to the DYLD_LIBRARY_PATH variable should work. I don't know what config to add the path to to make that addition permanent on OSX though.

Laravel 5.1 - `php artisan migrate` is giving 'PDOException'

I know this is a duplicate question however whatever I tried, unfortunately no luck. (To add, I am using MAMP)
I believe I successfully setup the database connection because, using the registration form (Auth/register), after submitting the form, I was getting the error PDO Exception: Driver not found before, but after changing to my MAMP to PHP 5.5.17 from the default(PHP 5.6.1), I started getting error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.users' doesn't exist, which I believe shows that the database connection is working and it's just the 'users table' is not created.
Here starts my problem. When I try to use php artisan migrate or migrate:{anything} in the terminal, it's throwing the error:
[PDOException]
could not find driver
But what I want to do is to use php artisan migrate to be able to create tables and migrate them.
Things I have tried:
I added <?php echo phpinfo(); ?> to if pdo files are successfully installed.
I get the result:
so I think it seems okay.
People were talking about opening /MAMP/bin/php/php5.6.1/conf/php.ini and adding extension=pdo_mysql.so in the code, but I have mine already placed there.
When I try php -i | grep PDO in the project root (/MAMP/htdocs/proj), I got:
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
php -i | grep Conf and `php --ini also outputs:
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.6.1/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.6.1/conf/php.ini but php artisan migrate still throwing the same error
SOLUTION:
I chose MAMP to use version 5.5.17 instead of 5.6.1 in the browser (from MAMP Preferences), however this time terminal was running the 5.6.1. What I did was first checking which PHP command and then, running the nano ~/.bash_profile command; and editing the version document. Now everything is up and running :)
What you see in the browser is that you have PDO enabled for PHP running through apache. But this does not mean you have it enabled for PHP running through CLI (in fact they are using two separate ini files). To confirm that you can try:
php -i | grep PDO
And you will see it is missing or not enabled. So what you need to do is to find which php.ini is using the PHP running through CLI and add the PDO module there:
php -i | grep Conf
It will output something like:
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

Unable to set up php MessDetector in PhpStorm on mac. #echo: command not found

I've installed phpmd and I'm trying to set up PhpStorm with it. When I add the path to the phpmd.bat file in PhpStorm "Settings | PHP | Mess Detector" and press validate I get the following error:
PHP Mess Detector
phpmd: /Applications/MAMP/htdocs/rentatool/vendor/phpmd/phpmd/src/bin/phpmd.bat:
#echo: command not found /Applications/MAMP/htdocs/rentatool/vendor/phpmd/phpmd/src/bin/phpmd.bat:
REM: command not found /Applications/MAMP/htdocs/rentatool/vendor/phpmd/phpmd/src/bin/phpmd.bat:
syntax error near unexpected token `(' /Applications/MAMP/htdocs/rentatool/vendor/phpmd/phpmd/src/bin/phpmd.bat:
`REM Copyright (c) 2008-2012, Manuel Pichler .'
I've installed phpmd with composer:
"require-dev": {
"phpmd/phpmd": "2.0.*"
}
and I'm running on Mac.
I found a chat were a person was having the same problem and solved it but I wasn't able to solve it the same way https://chat.stackexchange.com/transcript/6/2014/7/11
Any ideas to where the problem lies are greatly appreciated.
It worked when I set the path to the phpmd exec file instead of to the .bat file.