Mysql HY000 without any description

29 views
Skip to first unread message

aravael

unread,
Jun 5, 2019, 1:07:15 PM6/5/19
to Fat-Free Framework
Hello everyone. I have got a PDO exception `HY000` (without any error description) while I try to parse huge text file.
Here is my part of code:

$string = null;
if
(! feof($handle)) {
while (($buffer = fgets($handle)) !== false) {
list (
$id,$link
) = explode(' ',$buffer);
$string .= "('$id','$link'),";
if ($x === 100) {
$string = rtrim($string, ',');
$string .= ';';
try {
$this->model->multiInsert($string);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
$string = null;

$x = 0;
} else {
$x++;
}
}
if (! feof($handle)) {
// error
}
fclose($handle);
}

The code above reads textfile line by line as you can see. Method `multiInsert($string)` uses the next construction:
$this->db->exec("INSERT INTO `table` (`id`,`link`) VALUES $string ");

However, this one occurs when I use  `$this->db->exec()`, and there is no exception when `$this-db->pdo()->exec()`
What I am doing wrong? Cheers

PJH

unread,
Jun 5, 2019, 1:18:39 PM6/5/19
to Fat-Free Framework


On Wednesday, June 5, 2019 at 6:07:15 PM UTC+1, aravael wrote:
Hello everyone. I have got a PDO exception `HY000` (without any error description) while I try to parse huge text file.

You have a generic database error.
 
Here is my part of code:

[...]

try {
$this->model->multiInsert($string);
} catch (PDOException $e) {

I'd be dumping `$string` here to make sure it's syntactically correct.

If it is, try manually executing it outside of your application.

ved

unread,
Jun 5, 2019, 7:18:14 PM6/5/19
to Fat-Free Framework
Hi,

About not getting an exception description, are you getting an actual exception or just a php error?
For example, are you using a 4th parameter when initializing your database connection?
See this (taken from here).

$options = array(
    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, // generic attribute
    \PDO::ATTR_PERSISTENT => TRUE,  // we want to use persistent connections
    \PDO::MYSQL_ATTR_COMPRESS => TRUE, // MySQL-specific attribute
);
$db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=mysqldb','username','password', $options);

Note the first option which enables PDO to throw exceptions that you can then try and catch. I seem to remember it doesn't get enabled unless explicitly set.
Once using this option, maybe you can get a better exception description that can help further debug your issue.

Cheers


On Wednesday, June 5, 2019 at 6:07:15 PM UTC+1, aravael wrote:

Yaroslav Beregovoy

unread,
Jun 6, 2019, 10:36:18 AM6/6/19
to ved via Fat-Free Framework, Fat-Free Framework
Hi ved. This is a part of my connection code:
self::$DB = new \DB\SQL(
$f3->get('dsn'),
$f3->get('db_user'),
$f3->get('db_password'), [
\PDO::ATTR_PERSISTENT => true,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING,
    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
]);


As you see I have got an exception mode enabled. Regarding to your question about `error` or `exception`, I have an exception in the `try catch` block.
For now I didn`t find any solution... Considering the suggestion of mr. PJH, my sql query is syntactically correct, there is no error, and as I said with `$this->db->pdo()->exec()`
works fine.
As mr. PJH said, I`ve got a generic database error...


--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/1d240340-66cc-45ad-8742-0f32f38ef466%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

richgoldmd

unread,
Jun 6, 2019, 12:31:48 PM6/6/19
to Fat-Free Framework
Can you share the output of $db->log() after the error occurs?

richgoldmd

unread,
Jun 6, 2019, 12:45:14 PM6/6/19
to f3-fra...@googlegroups.com
Might I suggest also that you use replaceable parameters rather than string interpolation to create your sql query?

Though I do see that you are building a multi record insert, is the performance gain significant?

Reply all
Reply to author
Forward
0 new messages