php获取mysql中文后显示乱码,能帮修改一下吗
<?php
header("Content-type: text/html; charset=utf-8");
$dsn = 'mysql:host=localhost;dbname=pw9';
$db = new PDO($dsn,'root','');
$rs = $db->query('SELECT * FROM pw_bbs_threads');
while($row=$rs->fetch()){
print_r($row);
}
PDO_FETCH_NUM (integer)
Specifies that the fetch method shall return each row as an array indexed by column number as returned in the corresponding result set, starting at column 0.
PDO_FETCH_BOTH (integer)
Specifies that the fetch method shall return each row as an array indexed by both column name and number as returned in the corresponding result set, starting at column 0.
PDO_FETCH_OBJ (integer)
Specifies that the fetch method shall return each row as an object with property names that correspond to the column names returned in the result set.
PDO_FETCH_BOUND (integer)
Specifies that the fetch method shall return TRUE and assign the values of the columns in the result set to the PHP variables to which they were bound with the PDOStatement::bindParam() or PDOStatement::bindColumn() methods.
PDO_FETCH_COLUMN (integer)
Specifies that the fetch method shall return only a single requested column from the next row in the result set.
PDO_FETCH_CLASS (integer)
Specifies that the fetch method shall return a new instance of the requested class, mapping the columns to named properties in the class.
PDO_FETCH_INTO (integer)
Specifies that the fetch method shall update an existing instance of the requested class, mapping the columns to named properties in the class.
PDO_FETCH_FUNC (integer)
PDO_FETCH_GROUP (integer)
PDO_FETCH_UNIQUE (integer)
PDO_FETCH_CLASSTYPE (integer)
PDO_ATTR_AUTOCOMMIT (integer)
If this value is FALSE, PDO attempts to disable autocommit so that the connection begins a transaction.
PDO_ATTR_PREFETCH (integer)
Setting the prefetch size allows you to balance speed against memory usage for your application. Not all database/driver combinations support setting of the prefetch size.
PDO_ATTR_TIMEOUT (integer)
Sets the timeout value in seconds for communications with the database.
PDO_ATTR_ERRMODE (integer)
PDO_ATTR_SERVER_VERSION (integer)
PDO_ATTR_CLIENT_VERSION (integer)
PDO_ATTR_SERVER_INFO (integer)
PDO_ATTR_CONNECTION_STATUS (integer)
PDO_ATTR_CASE (integer)
Force column names to a specific case specified by the PDO_CASE_* constants.
PDO_ATTR_CURSOR_NAME (integer)
PDO_ATTR_CURSOR (integer)
PDO_ATTR_DRIVER_NAME (string)
Returns the name of the driver.
PDO_ATTR_ORACLE_NULLS (integer)
Convert empty strings to SQL NULL values.
PDO_ATTR_PERSISTENT (integer)
Request a persistent connection, rather than creating a new connection.
PDO_ATTR_FETCH_CATALOG_NAMES (integer)
Prepend the containing catalog name to each column name returned in the result set. The catalog name and column name are separated by a decimal (.) character.
PDO_ATTR_FETCH_TABLE_NAMES (integer)
Prepend the containing table name to each column name returned in the result set. The table name and column name are separated by a decimal (.) character.
PDO_ERRMODE_SILENT (integer)
Do not raise an error or exception if an error occurs. The developer is expected to explicitly check for errors. This is the default mode.
PDO_ERRMODE_WARNING (integer)
Issue a PHP E_WARNING message if an error occurs.
PDO_ERRMODE_EXCEPTION (integer)
Throw a PDOException if an error occurs.
PDO_CASE_NATURAL (integer)
Leave column names as returned by the database driver.
PDO_CASE_LOWER (integer)
Force column names to lower case.
PDO_CASE_UPPER (integer)
Force column names to upper case.
PDO_FETCH_ORI_NEXT (integer)
Fetch the next row in the result set. Valid only for scrollable cursors.
PDO_FETCH_ORI_PRIOR (integer)
Fetch the previous row in the result set. Valid only for scrollable cursors.
PDO_FETCH_ORI_FIRST (integer)
Fetch the first row in the result set. Valid only for scrollable cursors.
PDO_FETCH_ORI_LAST (integer)
Fetch the last row in the result set. Valid only for scrollable cursors.
PDO_FETCH_ORI_ABS (integer)
Fetch the requested row by row number from the result set. Valid only for scrollable cursors.
PDO_FETCH_ORI_REL (integer)
Fetch the requested row by relative position from the current position of the cursor in the result set. Valid only for scrollable cursors.
PDO_CURSOR_FWDONLY (integer)
Create a PDOStatement object with a forward-only cursor. This may improve the performance of your application but restricts your PDOStatement object to fetching one row at a time from the result set in a forward direction.
PDO_CURSOR_SCROLL (integer)
Create a PDOStatement object with a scrollable cursor. Pass the PDO_FETCH_ORI_* constants to control the rows fetched from the result set.
PDO_ERR_NONE (string)
Corresponds to SQLSTATE '00000', meaning that the SQL statement was successfully issued with no errors or warnings.