What is the best collation to use for MySQL with PHP? I'm wondering if there is a "best" choice for collation in MySQL for a general website where you aren't 100% sure of what will be entered? I understand that all the encodings should be the same, such as MySQL, Apache, the HTML and anything inside PHP. In the past I have set PHP to output in "UTF-8", but which collation does this match in MySQL? I'm thinking it's one of the UTF-8
undefined
mysqli_fetch_array()/mysqli_fetch_assoc()/mysqli_fetch_row() expects parameter 1 to be resource or mysqli_result, boolean given I am trying to select data from a MySQL table, but I get one of the following error messages: mysql_fetch_array() expects parameter 1 to be resource, boolean given or mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given This is my code: $username = $_POST['username']; $password = $_POST['password']; $result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username'); while($row = mysql_fetch_array($result)) { echo $row['FirstName']; } The same applies to
undefined
How to import an SQL file using the command line in MySQL? I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line. I have a Windows Server 2008 R2 installation. I placed the .sql file on the C drive, and I tried this command database_name < file.sql It is not working I get syntax errors. How can I import this file without a problem? Do I need to create a database first?
undefined
How to reset AUTO_INCREMENT in MySQL? How can I reset the auto-increment of a field? I want it to start counting from 1 again. Answer: You can reset the counter with: ALTER TABLE tablename AUTO_INCREMENT = 1 For InnoDB you cannot set the auto_increment value lower or equal to the highest current index. (quote from ViralPatel): Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is
undefined
Can I concatenate multiple MySQL rows into one field? Using MySQL, I can do something like: SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; and get: shopping fishing coding but instead I just want 1 row, 1 col: shopping, fishing, coding The reason is that I'm selecting multiple values from multiple tables, and after all the joins I've got a lot more rows than I'd like. I've looked for a function on MySQL Doc and it doesn't look like the CONCAT or CONCAT_WS functions accept result sets, so does anyone
undefined
How to output MySQL query results in CSV format? Is there an easy way to run a MySQL query from the Linux command line and output the results in CSV format? Here's what I'm doing now: mysql -u uid -ppwd -D dbname << EOQ | sed -e 's/ /,/g' | tee list.csv select id, concat("\"",name,"\"") as name from students EOQ It gets messy when there are a lot of columns that need to be surrounded by quotes, or if there are quotes in the results
undefined
UTF-8 all the way through I'm setting up a new server, and want to support UTF-8 fully in my web application. I have tried in the past on existing servers and always seem to end up having to fall back to ISO-8859-1. Where exactly do I need to set the encoding/charsets? I'm aware that I need to configure Apache, MySQL and PHP to do this - is there some standard checklist I can follow, or perhaps troubleshoot where the mismatches occur? This is