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");
Related
I am getting the following error while installing chamilo version 1.11.6.
Fatal error: can't use function return value in write context in /var/www/html/chamilo/main/inc/lib/api.lib.php on line 1772
My php version is 7.2.
This error appears because somehow the PHP version is not 7.2 (but rather <5.5) in the context in which you are executing the page.
Since PHP 5.5, the emty() function was changed to support function results.
See http://php.net/manual/en/function.empty.php
Note:
Prior to PHP 5.5, empty() only supports variables; anything else
will result in a parse error. In other words, the following will
not work: empty(trim($name)). Instead, use trim($name) == false.
My guess is the place where you change the PHP version in your control panel doesn't affect (or didn't affect yet) the place where Chamilo is being loaded.
Ask your hosting provider, maybe?
You can place a "info.php" file with the following content at the root of Chamilo and load it directly through the browser. This will tell you what version PHP is running at in the Chamilo directory:
<?php
phpinfo();
I bet it still shows PHP 5.4...
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.
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
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)
After recompiling php I get the following errors when I use php cli:
PHP Warning: PHP Startup: imap: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/ldap.so' - /usr/lib/php/modules/ldap.so: undefined symbol: third_arg_force_ref in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mbstring.so' - /usr/lib/php/modules/mbstring.so: undefined symbol: second_arg_force_ref in Unknown on line 0
PHP Warning: PHP Startup: mysql: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: mysqli: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: PDO: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module
Module compiled with module API=20050922
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mapi.so' - /usr/lib/php/modules/mapi.so: undefined symbol: fourth_arg_force_ref in Unknown on line 0
After some googling I found that the modules have to be updated, I tried:
pecl install <modulename>
and
pecl upgrade <modulename>
and
pear install -f pecl/<modulename>
but I got errors like:
configure: error: mysql_query missing!?
ERROR: `/tmp/pear/temp/PDO_MYSQL/configure' failed
Or errors like:
make: *** [sqlite_driver.lo]
Error 1 ERROR: `make' failed
Any idea how to update the modules?
If there was anything that I should have done before compiling please explain to me because I'm going to recompile php on other servers and I want to know the solution before I face the same problem again.
Thanks in advance.
PS: My OS is Linux (Redhat)
It looks like the problem you're having is that your php and module APIs are different, e.g.:
Module compiled with module API=20050922 <----- this
PHP compiled with module API=20090626 <----- and this should match.
I usually install extensions by compiling them from source, which seems to work a lot more reliably.
You'll need to use phpize
As an example, here's how I'd install APC:
wget http://pecl.php.net/get/APC-3.1.9.tgz
tar -xvzf APC-3.1.9.tgz
cd APC-3.1.9
phpize
./configure
make
sudo make install
This should work for all PECL extensions. Now, you also have other errors.. I would suggest going through your php.ini and disabling all extensions at first - then enable and fix one by one.
There's also an error about mysqli. If you're using php >= 5.0.0, then you'll need to re-compile php (with ./configure [....] --with-mysqli), otherwise the procedure above should work for it as well.
HTH