i think might deadlock issue, i'm reading table data. or simple can't see.
my $msqli
obj fine db access
but i'm bit stumped error.. being told clients
table not being locked lock tables
any suggestions welcome.. here php code
$mysqli = $globals['mysqli']; $mysqli->query("lock tables clients read, invoices read, estimates read"); $mysqli->query("set @inv='invoice'"); $mysqli->query("set @est='estimate'"); $sql = " (select @inv, name client, invoices.id, invoices.ref ref, invoices.addts ts \n" . "from `clients` , `invoices` \n" . "where invoices.user_id = " . $_session['user_id'] . " \n" . "and clients.id = invoices.client_id)\n" . "union all\n" . "(select @est, name client, estimates.id, estimates.ref ref, estimates.addts ts \n" . "from `clients` ,`estimates` \n" . "where estimates.user_id = " . $_session['user_id'] . " \n" . "and clients.id = estimates.client_id) \n" . "order ts desc limit 5"; if ($result = $mysqli->query($sql) or die(mysqli_error($mysqli))) { //do stuff here }
when run $sql
query in phpmyadmin successful... help..
********************solved (?) ******************
fixed (or seems be):
quote http://bugs.mysql.com/bug.php?id=6588
"you cannot use locked table multiple times in 1 query - use aliases that."
so query updated
$mysqli->query("lock tables clients_t read,clients read , invoices read, estimates read"); $mysqli->query("set @inv='invoice'"); $mysqli->query("set @est='estimate'"); $sql = " " . "(select @inv, name client, invoices.id, invoices.ref ref, invoices.addts ts " . "from `clients` clients_t , `invoices`\n" . "where invoices.user_id = " . $_session['user_id'] . " \n" . "and clients_t.id = invoices.client_id)\n" . "union \n" . "(select @est , name client, estimates.id, estimates.ref ref, estimates.addts ts\n" . "from `clients` ,`estimates` \n" . "where estimates.user_id = " . $_session['user_id'] . " \n" . "and clients.id = estimates.client_id)\n" . "order ts desc limit 5";
i needed lock alias table clients_t
. anyway future users hope helps.
a little nit picky wise such addslashes or mysql_real_escape_string $_session['user_id'] input avoid injection issues.
Comments
Post a Comment