mysql: SOURCE error 2?

Assuming you mean that you are trying to use the source command in order to execute SQL statements from a text file, the error number given appears to be passed through from the POSIX layer. Therefore, using this resource, we can deduce that the error value of 2 means “no such file or directory”. In short, you got the path … Read more

How can I loop through all rows of a table? (MySQL)

Since the suggestion of a loop implies the request for a procedure type solution. Here is mine. Any query which works on any single record taken from a table can be wrapped in a procedure to make it run through each row of a table like so: First delete any existing procedure with the same … Read more

Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction

You are using a transaction; autocommit does not disable transactions, it just makes them automatically commit at the end of the statement. What is happening is, some other thread is holding a record lock on some record (you’re updating every record in the table!) for too long, and your thread is being timed out. You … Read more

Usage of MySQL’s “IF EXISTS”

You cannot use IF control block OUTSIDE of functions. So that affects both of your queries. Turn the EXISTS clause into a subquery instead within an IF function In fact, booleans are returned as 1 or 0

Fatal error: Call to a member function bind_param() on boolean [duplicate]

The problem lies in: The prepare() method can return false and you should check for that. As for why it returns false, perhaps the table name or column names (in SELECT or WHERE clause) are not correct? Also, consider use of something like $this->db->conn->error_list to examine errors that occurred parsing the SQL. (I’ll occasionally echo the actual SQL statement strings and paste into phpMyAdmin to test, … Read more

SELECT * FROM multiple tables. MySQL

What you do here is called a JOIN (although you do it implicitly because you select from multiple tables). This means, if you didn’t put any conditions in your WHERE clause, you had all combinations of those tables. Only with your condition you restrict your join to those rows where the drink id matches. But there are still X … Read more