我试图将数据从字符串转换为float并将其插入MYSQL数据库。 $ data变量是一个字符串。这是我的SQL查询:
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
stockcode VARCHAR(8) NOT NULL,
lastprice FLOAT NOT NULL,
open FLOAT NOT NULL,
close FLOAT NOT NULL,
low FLOAT NOT NULL,
high FLOAT NOT NULL
)";
$rows = $table->getElementsByTagName("tr");
$i = 0;
foreach ($rows as $row) {
if ($i++ < 1) {
continue;
}
$a = array();
$cells = $row->getElementsByTagName('td');
$i = 0;
foreach ($cells as $cell) {
if ($i++ < 1) {
continue;
}
array_push($a, floatval($cell->nodeValue));
}
print_r($a);
var_dump($a);
echo "<hr/>";
$sql = "INSERT INTO $table (stockcode, lastprice, open, close, low, high)
VALUES ( '" . $data[0] . "', '" . $data[1] . "', '" . $data[4] . "', '" . $data[7] . "', '" . $data[5] . "', '" . $data[6] . "')";
但它仍然给我错误:PHP Catchable致命错误:类DOMElement的对象无法在第79行的/var/www/html/mysqlcon.php中转换为字符串
答案 0 :(得分:0)
您需要将浮点数放在两个引号之间
pointerevents
即使数字应该在两个引文之间