Does the MySQL-server and PHP5-MySQLi version have to match in order for a connection to be possible? I'm currently receiving the error below: I am running BSD.
"Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'..."
Here is the the connection info:
$info = "mysql:dbname=myDB;host=localhost";
$user = "dbUser";
$pw = "somePW";
return(new PDO($info, $user, $pw));
Here is my MySQL information:
mysql-server-5.5.24
php5-mysqli-5.4.3
I had this same issue on my CentOS install. I had tried to install imagick and hosed my install. When I removed all of my php files and reinstalled something wasn't working right.
I ran:
yum install php-pdo
yum install php-pdo_mysql
After doing those two lines I ran
service httpd restart
and everything came back up and running.
PDO uses database specific drivers to connect to database systems. It looks like you are missing the pdo_mysql driver that is required to connect to a MySQL database. There is some details on installing the driver on the pdo_mysql manual page, or there may be a BSD package that you can use (I am afraid I'm not familiar enough with BSD to offer specific advice).
Thanks to zerkms and John C for pointing me in the right direction. Below are the commands I used to install the driver:
#cd /usr/ports/databases/php5-pdo_mysql
#make install clean
#apachectl restart
Related
I'm trying to connect to Mongolab db server, but I get this error:
Fatal error: Class 'MongoClient' not found in /home/viviane/public_html/sk/zizi/head.php on line 33
I suspect it is related to the PHP Mongo Driver, but I don't know how. If I try to connect to a remote mongodb server
$uri = "mongodb://dzyasser:dzyasser#ds049624.mongolab.com:49624/serverdb";
$options = array("connectTimeoutMS" => 30000);
$connection = new MongoClient($uri, $options );
So why am I still getting this error when I'm trying to connect to a remote Mongodb server (Mongolab)?
Its look like you don't have MongoDB PHP extension in your system.
Try to install MongoDB PHP extension in order to solve your problems with the MongoClient class. This is how I setup MongoDB PHP extension in OS X.
Get MongoDB extension from PECL
$ sudo pecl install mongodb
Make a copy of php.ini.default
$ sudo cp /etc/php.ini.default /etc/php.ini
Put this line on php.ini than save
extension=mongodb.so
Check the installation using this command
php --re mongodb
Or create simple php document that contain phpinfo() function
If you get problem with writing the extension, please read this post.
I assume, the Mongo driver is installed and loaded.
If so, since the error message says the MongoClient class cannot be found, it might be caused by a namespace used in your script. If so, try
$connection = new \MongoClient($uri, $options );
Regardless of whether you are connecting locally or remotely, it seems PHP requires the mongo DB service to be running on your server. So install it like so:
a) Install mongodb service
$ sudo apt-get install -y mongodb
b) Add the php drivers if they are missing:
$ sudo apt-get install php5-dev php5-cli php-pear -y
$ sudo pecl install mongo
c) Then open your php.ini file and add to it the extension line "extension=mongo.so":
$ sudo vi /etc/php5/apache2/php.ini
> extension=mongo.so
d) Then restart apache
$ sudo service apache2 restart
Disclaimer: This example was tried on Ubuntu 14.04 LTS with Apache web-service and PHP5 installed. If your installation is different, follow the same approach but issue appropriate commands. If you have no access to SSH or sudoer privileges, contact someone who can help you do this.
I need to maintain a project for another person. This project connects PHP with Oracle, but when I set it up on Redhat, the system shows this error:
Call to undefined function oci_connect() in ...
I think I'm missing OCI8 extention and need to install it.
I read and tried this link, but I can't run yum install php-devel because Redhat shows that I do not have this package.
What is the best way to connect via PHP on a Linux box to a Remote Microsoft SQL Server.
The PHP will only ever run on a Linux box.
I've been trawling for the simplest answer for a while now.
Php 5.6
Ubuntu
sudo apt-get install php5.6-sybase freetds-common libsybdb5
AWS / Centos / Redhat
sudo yum install php56-mssql
After that, you can connect to the MsSql database through PHP with something like this:
<?php
$server = 'localhost';
$user = 'someUser';
$pass = 'somePassword';
$database = 'theDatabaseName';
try {
$pdo = new \PDO(
sprintf(
"dblib:host=%s;dbname=%s",
$server,
$database
),
$user,
$pass
);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "There was a problem connecting. " . $e->getMessage();
}
$query = "SELECT * FROM TestSchema.Employees";
$statement = $pdo->prepare($query);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($results);
You can troubleshoot MsSQL with something like this on the command line:
tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename
To install tsql you can run this:
Installation of SQL binaries for testing on any PHP version
sudo apt install freetds-bin
Php 7+
Microsoft has native drivers we can use. Full instructions are here (Redhat / Ubuntu / Others).
That link also contains required steps to install Ms SQL server on your dev machine (working on Ubuntu, doesn't work on AWS, but you can just spin up an RDS instance there).
It also contains basic instructions on how to create test tables and data in the database, and PHP connectivity code.
You can also install the components for a newer version of PHP like this:
sudo apt-get install php7.2-sybase freetds-common libsybdb5
you must to install mssql driver for php on linux.
this is a best tutorial for you.
Try: For Ubuntu
sudo apt-get install php5-sybase php5-odbc freetds-common
Edit freetds.conf then connect MSSQL server with this PHP.
After searching and trying out the many suggestions here and in other posts, and spending a lot of time, a colleague suggested trying ADO.
As we already had an ADO enabled PHP install, it literally took less than 10 minutes to get up and running.
If your serious about connecting from Linux PHP to MS-SQL, consider ADO.
It's interesting to note that every answer here proposes one solution to the problem rather than answering the question asked which was which is the "best" solution. Unfortunately the OP forgot to tell us what the criteria were for "best".
Nobody so far has mentioned odbc. While this entails both configuring the odbc driver for connecting to the database and enabling the php extension, this method provides the best isolation of the php code from the underlying database making it easier to port the code later.
The microsoft provided drivers for php should give good compatibility but only support v7 up of php.
You may prefer to stick with the functionality provided by your Linux distro to ensure you have a supportable product and/or automated patch management. An alternative to odbc here may be the freetds driver but you didn't tell us anything about which Linux distro this is.
Get the sqlsrv extension from microsoft for php http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
I installed unixODBC by using apt-get install, and now when I try to use odbc_connect() is still get this error.
PHP Fatal error: Call to undefined function odbc_connect()
what do i need to do to configure it to work with php? I have been looking online but I can't really figure it out.
I think you need to install php5-odbc also. unixODBC provides the driver manager, but you need the PHP code that calls it.
Had the same issue on CentOS 6.3 with PHP 5.3.16. But the fix was to use yum to install php-odbc.
yum install php-odbc
Did you add it to your LD_LIBRARY_PATH? Check the documentation for your server, it may require third-party libraries to be in a specific sub-directory, or have some other mechanism for finding them. If so, you should be able to create a symbolic link to the library. That way, if it gets updated, your server will automatically use it.
We had this problem also. We installed php5-odbc, and still had the problem. Turns out we needed to reboot Linux for php to see the function. Recycling Apache was not enough!
Make sure to enable odbc extension for your Apache by a2enmod odbc.
Then check if exists by: apache2ctl -M.
If you don't have this extension, install via apt-get install php-odbc (use yum in case of CentOS).
See also: Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS.
My project works fine on my local. When i put it on Debian, I am facing an error:
PDO Connection Error: SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 110
I searched it on the internet, everyone thinks its because of databases.yml file. I tried lots of one but could not fix the prob.
For the PDO, I think all you have to activate it is to add in your php.ini the
extension=pdo.so
line.
For curl and imagemagick extensions, are the modules installed?
sudo apt-get install php5-curl php5-imagick