Query (' SELECT * from Pw_bbs_threads '), while ($row = $rs->fetch ()) {Print_r ($row);}
1. File Encoding UTF8
2.mysql encoded UTF8
3. Browser Encoding UTF8
Search a lot, found that someone said to set names UTF8, but in my this code do not know how to write, Trouble Gao modified thank you
Reply to discussion (solution)
$db->query ("SET NAMES UTF8");
$db->query ("SET NAMES UTF8");
What's the sentence behind this sentence?
$db->query ("SET NAMES UTF8");
OK
But a little confused, in the PHP manual
Pdostatement pdo::query (String $statement) pdostatement pdo::query (string $statement, int $PDO:: fetch_column, int $c Olno) pdostatement pdo::query (string $statement, int $PDO:: Fetch_class, String $classname, array $ctorargs) Pdostatem Ent pdo::query (string $statement, int $PDO:: Fetch_into, Object $object)
The parameter inside is the first argument string $statement?
That is true..
It's better to write like this
$db = new PDO ($dsn, ' root ', ' ', array (Pdo::mysql_attr_init_command = "Set Names UTF8"));
Do not forget to write $db->query ("SET NAMES UTF8"); and the problem
It's better to write like this
$db = new PDO ($dsn, ' root ', ' ', array (Pdo::mysql_attr_init_command = "Set Names UTF8"));
Do not forget to write $db->query ("SET NAMES UTF8"); and the problem
Thank you very much, the line of the pass, in addition to consult, I consulted php.net PDO class, only the class summary information (inside the class method, but there is no class of static variables, such as Pdo::mysql_attr_init_command why I can't find it on top, Where can you see it?
It's not in the manual, is it?
Pre-defined constants
The following constants are defined by this extension and are therefore valid only if the extension is compiled into PHP or is dynamically loaded at run time.
Pdo_param_bool (integer)
Represents a Boolean data type.
Pdo_param_null (integer)
Represents the SQL NULL data type.
Pdo_param_int (integer)
Represents the SQL INTEGER data type.
Pdo_param_str (integer)
Represents the SQL CHAR, VARCHAR, or other string data type.
Pdo_param_lob (integer)
Represents the SQL large object data type.
Pdo_param_stmt (integer)
Pdo_param_input_output (integer)
Specifies the parameter is an INOUT parameter for a stored procedure. You must bitwise-or the value with an explicit pdo_param_* data type.
Pdo_fetch_lazy (integer)
Specifies that's the fetch method shall return each row as a object with variable names, correspond to the column names Returned in the result set. Pdo_fetch_lazy creates the object variable names as they are accessed.
PDO_FETCH_ASSOC (integer)
Specifies that-the-fetch method shall return each row as a array indexed by column name as returned in the corresponding Result set. If The result set contains multiple columns with the same name, PDO_FETCH_ASSOC returns only a single value per column Nam E.
Pdo_fetch_named (integer)
Specifies that-the-fetch method shall return each row as a array indexed by column name as returned in the corresponding Result set. If The result set contains multiple columns with the same name, Pdo_fetch_named returns an array of values per column name .
Pdo_fetch_num (integer)
Specifies that-the-fetch method shall return each row as a array indexed by column number as returned in the Correspondin G result set, starting at column 0.
Pdo_fetch_both (integer)
Specifies the fetch method shall return each row as an array indexed by both column name and number as returned in th E corresponding result set, starting at column 0.
Pdo_fetch_obj (integer)
Specifies that's the fetch method shall return each row as a object with a property names this correspond to the column names Returned in the result set.
Pdo_fetch_bound (integer)
Specifies the fetch method shall return TRUE and assign the values of the columns in the result set to the PHP Variab Les to which they were bound with the Pdostatement::bindparam () or Pdostatement::bindcolumn () methods.
Pdo_fetch_column (integer)
Specifies that the Fetch method shall return is 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 Propertie s in the class.
Pdo_fetch_into (integer)
Specifies that the Fetch method shall update a existing instance of the requested class, mapping the columns to named Pro Perties 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, the connection begins a transaction.
Pdo_attr_prefetch (integer)
Setting The prefetch size allows you-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 is 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 is separated by a decimal (.) character.
Pdo_errmode_silent (integer)
Do not raise a error or exception if an error occurs. The developer is expected-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 could 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 is successfully issued with no errors or warnings.