这是脚本:
<?php
echo "connection receiving";
$value0=$_GET['value0'];
$opendb=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db('arduino',$opendb);
if ($opendb){
echo " database open.";
if (!$db) {
echo mysql_error();
}
$query = "INSERT INTO analoog0 VALUES(curdate(), curtime(), '$value0');";
/* Run the query */
$result= mysql_query($query)or die(mysql_error());
mysql_close($opendb);
echo "values written = $value0";
}
?>
当我运行 /write.php?value0=25 时,我得到未知数据库'arduino'未选择数据库
答案 0 :(得分:1)
试试这个:
$con = mysqli_connect("localhost", "root", "");
// check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$value0 = $_GET['value0'];
mysqli_query($con, "INSERT INTO arduino.analoog0 VALUES(curdate(), curtime(), '" . $value0 . "')");
echo "values written = " . $value0;
mysqli_close($con);