PDO MySQL
try{
$votePDO = new PDO ("Mysql:host=127.0.0.1;dbname=legou", ' Root ', ' 2sinilei. ', array (pdo::attr_persistent = true));
$votePDO = new PDO ();
$pdoconn->setattribute (pdo::attr_persistent,true);
echo "Success
";
}
catch (Pdoexception $e) {
echo $e->getmessage ();
}
$result = $votePDO->query ("SELECT * from Uz_types");
Var_dump ($result);
$votePDO->query ("INSERT into uz_types (TypeName) VALUES (' Ah ah ')");
echo "count=". $count. "
";
$result->setfetchmode (PDO::FETCH_ASSOC);
Print_r ($result);
if (empty ($result))
{
echo "NULL";
}else
{
echo "has". Count ($result). " Datas ";
}
echo count ($result);
foreach ($result as $k = $v)
{
echo $v [' TypeName '];
};
?>
Here is the result of the page output
Success
BOOL (FALSE) count=
Null1
//
PHP.ini has been configured well.
There is no link on the error note, but why is this output?
Solve the solution Ah ~
Reply to discussion (solution)
Var_dump ($result);
$arr = $votePDO->errorinfo ();
Print_r ($arr); Post this result and see
Array ([0] = S1000 [1] = 0 [2] = Unknown Initial character Set index ' "received from server. Initial client Character set can is forced via the ' characterencoding ' property. ) count=
Wrong coding??
Print out success
Represents $votePDO = new PDO ("Mysql:host=127.0.0.1;dbname=lego ... Perform the correct
Print out bool (false)
Represents $result = $votePDO->query ("SELECT * from Uz_types"); Execution failed
Print out count=
Normal
echo "count=". $count. "
"; The $count is not assigned a value
Since $result is false,
Then if (empty ($result)) is established
It's normal to print out null.
Print out success
Represents $votePDO = new PDO ("Mysql:host=127.0.0.1;dbname=lego ... Perform the correct
Print out bool (false)
Represents $result = $votePDO->query ("SELECT * from Uz_types"); Execution failed
Print out count=
Normal
echo "count=". $count. "
"; The $count is not assigned a value
Since $result is false,
Then if (empty ($result)) is established
It's normal to print out null.
Why does the query fail to solve the problem?
Your library, how do I know why I failed
Print_r ($votePDO->errorinfo ());
Look at the error message
Your library, how do I know why I failed
Print_r ($votePDO->errorinfo ());
Look at the error message
I posted it on the 2 floor, trouble to see.
Var_dump ($result);
$arr = $votePDO->errorinfo ();
Print_r ($arr); Post this result and see
Array ([0] = S1000 [1] = 0 [2] = Unknown Initial character Set index ' "received from server. Initial client Character set can is forced via the ' characterencoding ' property. ) count=
$votePDO = new PDO ("Mysql:host=127.0.0.1;dbname=legou", ' Root ', ' 2sinilei. ', array (pdo::attr_persistent = True,pdo :: Mysql_attr_init_command = ' SET NAMES \ ' utf8\ '));
Let's try this.
$votePDO = new PDO ("Mysql:host=127.0.0.1;dbname=legou", ' Root ', ' 2sinilei. ', array (pdo::attr_persistent = True,pdo :: Mysql_attr_init_command = ' SET NAMES \ ' utf8\ '));
Let's try this.
Can be read out, is the coding problem code is not unified reading data. Thank you for the bamboo.