kohana db exception [0] - php

I have a big problem with connecting to mysql database. I tried everything and nothing worked.
If i try to connect on localhost with xampp to db on kohana (3.1.2), i get this error:
Database_Exception [ 0 ]: ~ MODPATH\database\classes\kohana\database\mysql.php [ 67 ]
but if i try run it on some server, it runs there and i dont know why, because everything is same (except db user and password).
I thought that it can be with mysql config, but i dont know what there.

I just came across this problem and figured out what it was so even though this question is old, people having this problem should know the answer.
Basically when you get this error its because your using a version of php 5.5+.
mysql_connect(...) is a depreciated function starting in php 5.5 and above so the call in the framework is wrapped around a try/catch but the output from the catch doesn't give you any details about the error for whatever reason but if you remove the try/catch you'll see the real php error is simple saying mysql_connect is depreciated and will be removed in the future and to use mysqli instead.
To fix this open index.php in your root and basically you need to change the error_reporting(...) call to tell it not to error on depreciation errors which you can do like so to report all errors except warnings and deprecations.
error_reporting(E_ALL ^ (E_WARNING | E_DEPRECATED));
Another fix is to change your database config file to connect via PDO instead of mysql.

I checked in Kohana 3.2, and there it means it can't connect to your database and throws an exception on that. But just go to the line 67 of the mysql.php file and check if the exception is triggered just after trying to connect to the DB.
Check your credentials in database config and make sure your MySQL server is up and running.

Related

I can't handle mysqli connect exception, because php always shows error

My problem is that I'm trying to make exception-handling, so if my page can not connect to the mysql database, it should write an error message that I made. It partly works, I can see my error message, BUT I also see two additional php errors.
Here is a picture:
Here is the code:
if(!mysqli_connect($server, $user, $passw, $db)) //line 12
$_SESSION['page'] = "conn_err";
I have tested with echo, the variables have values, they are not empty or null!
The variables are test values, so they are wrong, to test if the exception handling works. Btw., I'm on localhost, and I'm using wampserver.
Soo... I want if only that one error message would be visible I made.
I tried to solve the problem with try-catch, also tried with a connection variable and an if statement, but nothing worked. Any ideas?
Thanks!
Edit:
I forgot the versions...
PHP version: 5.5.12
Apache version: 2.4.9
MySQL version: 5.6.17

Call to undefined function mysql_connect() on Heroku. (PHP works fine locally but not on heroku- why?)

Thanks for your help in advance. I have been working on this bug for more than 12 hours now.
There is an AJAX signup form in my Heroku site which runs on MySQL and is connected to ClearDB Database. I can successfully send data to the database on my local server (MAMP). However, I cannot do the same on the server.
The requests cannot get send to the database and gets stuck at loading. Upon inspection I realise it is a PHP 500 Error.
I found the key problem in the Heroku logs. 2014-11-24T15:02:31.238493+00:00 app[web.1]: [24-Nov-2014 15:02:30 UTC] PHP Fatal error: Call to undefined function mysql_connect() in /app/index.php on line 5
Line 5 of the index.php is mysql_connect('hostname', 'username, 'password');
I have tried running php_getinfo(); and found that there is no MySQL support in the server. On a side note, I have MySQL support in my localhost.
The server php.ini paths are as such: Configuration File (php.ini) Path /app/.heroku/php/etc/php & Loaded Configuration File /app/vendor/heroku/heroku-buildpack-php/conf/php/php.ini
What should I do?
mysql_* functions are deprecated and actually removed in the next PHP version. Check out mysqli.
Worth noting that you can enable mysql_* on Heroku via composer.json. This is documented in Heroku's devcenter docs on PHP support.
Also recommend you consider using a more modern MySQL library, though :)

"Attempt to read a row while there is no result set associated with the statement" on Linux server but no error on Windows computer

I am using mysqli to connect to a MySQL database with PHP.
As I am programming on a windows computer with error_reporting(E_ALL) and mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
While coding I get neither errors nor warnings. But on the server I get
Fatal error: Uncaught exception 'mysqli_sql_exception' with message
'Attempt to read a row while there is no result set associated with the statement'
I think this is a little bit strange.
The error is thrown, if you call mysqli_stmt::fetch() on a statment that provides no results, e.g. after executing an insert, update or delete query, or if you already called mysqli_stmt::free_result().
There was a part of my code that was messed up and I fixed it already.
But my question is, why is this error not thrown on my development platform?
Is there an option in the php.ini or somewhere I have to set?
I now tested some settings and the result is:
If you use "MySQL Client Library" instead of "MySQL Native Driver" you get the error described in the question. I don't know, why the server were not using mysqlnd, as it is default since PHP 5.4.0 and there seams to be no reason to not use it but some advantages, so I changed it.
But however, one should not try to fetch results from an insert, update or delete query or after freeing the result. This is just senseless.

codeigniter auto loading the database even though i removed from autoload.php

I am developing a site in php and I am using codeigniter as framework.
I removed database in $autoload['libraries'] from autoload.php. But it is showing error when i removed database credentials from database.php.
I don't understand the problem here.I must be able to load the site without a database connection. According to the documentation I just shouldn't load any database. But it is throwing an error. How to resolve this issue?
The error is:
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\mlp\system\database\DB_driver.php
Line Number: 124
You may be calling database library by loading it somewhere in your script. by using $this->library->load('database') try removing that. ... ELSE ...Try to clear your browser cache... Refresh the project once... Restart apache(if it doesnt work even after the previous two).
If you removed database from autoload.php it is not possible to show the error message, if this message is showing you had used the library any of your controller.

Uncaught PDOException: fetch mode requires colno - but only on production server

I've been migrating a website from one server to another. The code is massive, so naturally I've had my share of problems. I believe they're all solved except for this persistent one:
On a particular page, I get the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: fetch mode requires the colno argument' in /home/username/public_html/admin/lib/database.inc.php:59
The line referenced:
$myResult->setFetchMode(PDO::FETCH_COLUMN);
I've been back and forth through the PDO documentation, so my diagnosis was originally that setting the fetch mode to PDO::FETCH_COLUMN required also setting a column number - no great deduction there. So I tried a value of 0 as the second argument. The page spent more than 30 seconds loading and got a PHP timeout. Same for a value of 1, and then I decided this wasn't the path to success.
Now, the really perplexing thing is that this site works perfectly on my local test machine without any modification, as well as on the original production server. I don't have easy access to the specs on the old server, but I know that those of my local test machine match those of the new server pretty damn closely.
Specifically:
Local PHP: 5.3.3
Remote PHP: 5.3.4
Local MySQL: 5.1.37
Remote MySQL: 5.0.91
Since I know the code is good with some configuration, I'm hoping someone knows the magic switch I can flip.
--EDIT--
Even with error_reporting set to E_ALL | E_STRICT on the local machine, this PDO exception doesn't appear.
Solved. Don't ask me why, but downgrading PHP to a particular version - as recommended by the original devs - did the trick. Nevermind that it was working fine locally with a more recent version. It just worked.
Old question I know, but I was getting the same error and thought I'd post what I found. I solved it by using prepared statements and passing PDO::FETCH_COLUMN to fetchAll().
$query = $database->prepare($sql);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_COLUMN);
I don't know why it works that and not with $database->query(). I don't need prepared statements here because I am not passing any parameters to the SQL, but it works so I roll with it. Hopefully that helps someone else who has this same error.

Categories