I am getting this error when I'm trying to connect using PDO.
General error: 1651 Query cache is disabled; restart the server with query_cache_type=1 to enable it
I do not have access to MySQL terminal. I only have access to phpmyadmin via cPanel.
How can I fix this?
I tried this :-
try
{
$s = $conn->query("SET query_cache_type = 1");
}
catch(PDOException $e)
{
echo $e->getMessage();
}
But this didn't work.
How can I fix this?
This is a strange behavior of query_cache_type such that cannot be enabled if it wasn't enabled when the mysqld process started. But if it was enabled at startup, you can set query_cache_type "off" and then back on again if you need to.
That said, I would strongly encourage you to reconsider using the query cache at all. MySQL 8.0 has retired support for the query cache and removed it from the product. It's still a feature in MySQL 5.7, but it's deprecated as of 5.7.20.
On mac it worked after executing below command
sudo /your-path-to-mysql/mysql.server start --query-cache-type=1
sudo /usr/local/mysql/support-files/mysql.server start --query-cache-type=1
try this!
Related
I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
and succesfully execute queries in the database.
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
Here is the test script:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.
php -m does show PDO and pdo-dblib.
Any ideas where I can look next?
Update: This was fixed. I missed in freetds.conf:
[global]
# TDS protocol version
tds version = 8.0
It was originally set to 4.5 instead of 8.
The fix for me was with three steps:
First, I edited /etc/freetds/freetds.conf and changed the tds version like this:
tds version = 8.0
The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.
Lastly, to connect properly, I had to restart networking as #user1054844 mentioned as this:
/etc/init.d/networking restart
After all these steps, I was able to connect and work with the SQL Server database.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
Guide is here: FreeTDS And pDO_dblib On cPanel
I'm trying to get a PHP 5.3.10 installation on Ubuntu 12.04 to connect to a a remote SQL Anywhere 12 (Sybase?) server using ODBC (unixODBC). However, PHP's execution halts at odbc_connect().
PHP code:
$odbc = odbc_connect('DSN=TP189902;', 'username', 'password');
if ($odbc)
{
echo 'Connected';
}
else
{
echo 'Failed: '.odbc_error($odbc);
}
So regardless of whether or not it connects, it should be outputting one of the echos, but it doesn't. If I try using PHP's PDO library instead, I get the same result.
My unixODBC setup looks like the following. And this might be where my mistake is, because I've never setup ODBC on linux before and am not very familiar with it.
odbcinst.ini
[SQL Anywhere 12]
Description = SQL Anywhere 12
Driver = /opt/sqlanywhere12/lib64/libdbodbc12.so
Setup = /opt/sqlanywhere12/lib64/libdbodbc12.so
odbc.ini
[TP189902]
Description = TP189902
Uid = username
Pwd = password
Driver = SQL Anywhere 12
ServerName = 189902
CommLinks = tcpip(Host=1.2.3.4)
DatabaseName = DB189902
I've also tried a ton of alternatives, such as using the driver's path for the Driver value, using Host=1.2.3.4 instead of CommLinks, etc.
Also the command isql -v TP189902 username password doesn't output anything unless I give it a fake DSN so that it outputs and error.
I've also verified that libdbodbc12.so is the same architecture as isql and that it has all of it's dependencies.
On top of this, I have very similar setup on a Windows 7 machine running WAMP, that connects just fine (with both the ODBC and PDO library). I used the same DSN details on it.
Edit: I've also tried this to skip the DSN, but it gives the same result. It also works on the Windows box.
$odbc = odbc_connect('Driver={SQL Anywhere 12};Server=189902;CommLinks=tcpip(Host=1.2.3.4);', 'username', 'password');
I don't use PHP these days but here are some things I've spotted:
I would totally ignore php until you get isql working.
I'm assuming it is a typo that you say your system ini file is "odbcinstr.ini" - it should be "odbcinst.ini".
How do you know you are looking at the right odbc ini files - run odbcinst -j to check the locations unixODBC is using.
I know where that "[ODBC Data Sources]" section comes from (iodbc) but it not at all necessary for unixODBC - just delete the first 2 lines of your odbc.ini file.
your isql line is probably missing a username and password - it should be "isql -v TP189902 username password". I cannot for the life of me see why it would output nothing at all.
Ultimately the issue was getting the LD_LIBRARY_PATH set to /opt/sqlanywhere12/lib64 for Apache.
Setting it in /etc/environment got isql -v TP189902 and php connect.php working when called from any shell user, but not Apache.
To get Apache to see it, I had to edit /etc/init.d/apache2 and change
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
to
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sqlanywhere12/lib64".
And then restart the Apache service.
Various other methods I found online to do this did not work.
One caveat is that with the path set, unixODBC still won't read my system DSN file for some reason. So to get Apache to access the DSN, I had to make a user DSN file (.odbc.ini) in /var/www, as that's the Apache user's (www-data) home folder.
I'm trying to learn Yii, but I'm stuck with a very persistent error that rises whenever I use yiic.
First system details: Ubuntu 13.04 with apache2, php 5.5.3 and mysql 5.5.3.
I run/yiic migrate
inside /protected of the webapp I'm developing.
I get the error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/yii/framework/db/CDbConnection.php:382
Which seems to be because at line 382 of CDbConnection.php, the script checks if pod_mysql is installed, but can't find it.
`if($this->_pdo===null)
{
if(empty($this->connectionString))
throw new CDbException('CDbConnection.connectionString cannot be empty.');
try
{
Yii::trace('Opening DB connection','system.db.CDbConnection');
$this->_pdo=$this->createPdoInstance();
$this->initConnection($this->_pdo);
$this->_active=true;
}
catch(PDOException $e)
{
if(YII_DEBUG)
{
throw new CDbException('CDbConnection failed to open the DB connection:'.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
}
else
{
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
throw new CDbException('CDbConnection failed to open the DB connection.'
,(int)$e->getCode(),$e->errorInfo);
}
}
}
^^ Here is the relevant snippet of code.
The result of running
php -i|grep PDO gives
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
So my problem seems to be that only the sqlite driver is running. However, I've ensured to check that php-mysql is installed (as pdo_mysql is deprecated and is inside this package). I've ran out of ideas on what to do, and will appreciate any and all help!!
Thanks in advance!
Console applications have their own config stored in protected/config/console.php. Please make sure you've got a database component configured there.
This problem is from your phpcli.ini instead of php.ini. in your phpcli.ini you should add :
extension=php_pdo_mysql.dll
as in php.ini
I have been trying to figure out which dll and how to use it to connect to sql server.
It was much easier using the old php_mssql.
I am using Xampp on WinXP Pro SP3. I have been unable to figure out how to connect, i have search the manual, and none of the command's work.
I get PDO Error Driver Not Found
extension-php_pdo_sqlsrv_54_ts.dll
extension=php_sqlsrv_54_ts.dll
I realized that I must use the SQLSERV 2.0 Drivers. But which dll is the correct one? And what syntax must I use to connect and run queries?
Thank you.
One way of doing this is using FreeTDS for Windows
I am assuming you have PHP >5.3
Download this http://download.moodle.org/download.php/dblib/php53/DBLIB_TS.zip
Add this line to your php.ini extension=php_dblib.dll
You will also need to make a file called freetds.conf in the root directory of your PHP installation.
It should look something like this:
[global]
host = xxx.xxx.xxx.xxx (host name or ip of the MSSQL server)
port = 1433
client charset = UTF-8
tds version = 8.0
text size = 20971520
Restart Apache and try running this script:
<?php
$link = mssql_connect('localhost', 'db_user', 'db_password');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
?>
hit me up on fb if this does not work ;)
I am trying to connect to my oracle database using PDO but I am getting Class PDO not found error. I have checked that PDO is enabled and it appears so. Still I am not able to trace why I am getting this error. Here is my configure command,
cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack"
"--with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\template"
"--with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build"
"--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared"
PHP ver : 5.2.8
Oracle: 10.2
This is the code I am using to connect to the db.
try{
$conn = new PDO("oci:dbname=".$oc_db,$oc_user,$oc_pass);
}catch(PDOException $e){
echo ($e->getMessage());
}
Can there be any other reason that I am getting this error? Any help appreciated.
This generally means the PDO extension in question isn't compiled and set up so PHP can use it. What operating system are you compiling PHP on?
I'm not sure if PDO core module is compiled if you only specify to compile the oracle extension of it (PDO-OCI).
You should check out the PHP manual regarding how to install and enable the PDO module.
You should look at these sites:
http://is.php.net/manual/en/pdo.installation.php
http://is.php.net/manual/en/ref.pdo-oci.php
Check my question I troubleshoot this and other errors but then Im stuck,
No records found ...Agiletoolkit and Oracle. Grid/CRUD elements
My Oracle connection string in agiletoolkit config-default.php file looks like this:
$config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );
To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.
Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:
class DB_dsql_oci extends DB_dsql {
function limit($cnt,$shift=0){
$cnt+=$shift;
$this->where('NUM_ROWS>=',$shift);
$this->where('NUM_ROWS<',$cnt);
return $this;
}
function render_limit(){
return '';
}
}
and placed it at: ...atk4\lib\DB\dsql
To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';
I manage to run the database test, and it says "Successfully connected to database."