How to change mysql to mysqli?

The first thing to do would probably be to replace every mysql_* function call with its equivalent mysqli_*, at least if you are willing to use the procedural API — which would be the easier way, considering you already have some code based on the MySQL API, which is a procedural one. To help with … Read more

MySQLi prepared statements error reporting [duplicate]

Each method of mysqli can fail. Luckily, nowadays mysqli can report every problem to you, all you need is ask. Simply add this single line to the connection code, mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); And after that every error will reveal itself. No need to test any return values ever, just write your statements right away: $stmt … Read more

Example of how to use bind_result vs get_result

Although both methods work with * queries, when bind_result() is used, the columns are usually listed explicitly in the query, so one can consult the list when assigning returned values in bind_result(), because the order of variables must strictly match the structure of the returned row. Example 1 for $query1 using bind_result() $query1 = ‘SELECT … Read more

On a function that gets settings from a DB I ran into the error [duplicate]

The problem lies in: $query = $this->db->conn->prepare(‘SELECT value, param FROM ws_settings WHERE name = ?’); $query->bind_param(‘s’, $setting); 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 … Read more

Do I have to guard against SQL injection if I used a dropdown?

Yes you need to protect against this. Let me show you why, using Firefox’s developer console: If you don’t cleanse this data, your database will be destroyed. (This might not be a totally valid SQL statement, but I hope I’ve gotten my point across.) Just because you’ve limited what options are available in your dropdown … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)