我正在尝试将数据从MySQL数据库存储到本地SQLite数据库。问题是我得到了超过500字的艺术家描述。我可以在我的屏幕上打印艺术家ID和艺术家名称,但似乎无法显示艺术家描述,除非我使用substr($ artist_description,0,397)。 0,397显示屏幕上的所有397个字符,但当我将其更改为398时,它不显示任何内容。
<?php
$artist_id = $_GET['artist_id'];
mysql_connect("localhost", "root", "")
or die("Failed to connect to database.");
mysql_select_db("testdb");
$query = "SELECT * FROM artist WHERE artist_id=$artist_id";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['artist_name'];
echo '<br />';
echo $row['artist_description'];
$artist_name = $row['artist_name'];
$artist_description = $row['artist_description'];
?>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var db = openDatabase('mydb', '3.0', 'Test DB', 20 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id UNIQUE, artist_name, artist_description TEXT)');
tx.executeSql('INSERT INTO LOGS (id, artist_name, artist_description) VALUES ("<?=$artist_id?>", "<?=$artist_name?>", "<?=substr($artist_description, 0, 397)?>")');
msg = '<p>Log message created and row inserted.</p>';
document.querySelector('#status').innerHTML = msg;
});
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).id + "</b> " + results.rows.item(i).artist_name + "<br>" + results.rows.item(i).artist_description + "</p>";
document.querySelector('#status').innerHTML += msg;
}
}, null);
});
</script>
</head>
<body>
<div id="status" name="status">Status Message</div>
</body>
</html>
*编辑:打印出'n,ó,&amp;等