Why am I returning empty records when querying in mysql with php?
Posted
by Brian Bolton
on Stack Overflow
See other posts from Stack Overflow
or by Brian Bolton
Published on 2010-03-09T04:25:20Z
Indexed on
2010/03/09
4:36 UTC
Read the original article
Hit count: 251
I created the following script to query a table and return the first 30 results. The query returns 30 results, but they do not have any text or information. Why would this be?
The table stores Vietnamese characters. The database is mysql4.
Here's the page: http://saomaidanang.com/recentposts.php
Here's the code:
<?php
header( 'Content-Type: text/html; charset=utf-8' );
//CONNECTION INFO
$dbms = 'mysql';
$dbhost = 'xxxxx';
$dbname = 'xxxxxxx';
$dbuser = 'xxxxxxx';
$dbpasswd = 'xxxxxxxxxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd ) or die('Error connecting to mysql');
mysql_select_db($dbname , $conn);
//QUERY
$result = mysql_query("SET NAMES utf8");
$cmd = 'SELECT * FROM `phpbb_posts_text` ORDER BY `phpbb_posts_text`.`post_subject` DESC LIMIT 0, 30 ';
$result = mysql_query($cmd);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="ltr">
<head>
<title>recent posts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>
<?php
//DISPLAY
while ($myrow = mysql_fetch_row($result))
{
echo 'post subject:';
echo(utf8_encode($myrow ['post_subject']));
echo 'post text:';
echo(utf8_encode($myrow ['post_text']));
}
?>
</p>
</body>
© Stack Overflow or respective owner