我试图将一些变量,图像和pdf文件保存到我的mysql数据库中。 (对图像和pdf文件使用longblob)。这样做我得到以下错误:
Warning: mysql_connect(): Access denied for user
&安培;
Warning: mysql_query() expects parameter 2 to be resource, boolean given
我已查看过拨款表
GRANT USAGE ON *.* user....
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES
说实话,我甚至不确定代码是否有效,但我想首先至少消除错误。有谁知道我可以解决这个问题以及我哪里出错了?任何代码示例都非常感谢。
require_once __DIR__.'/config.php';
/*** connect to db ***/
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_USERNAME, DB_USERNAME, DB_PASSWORD);
$conn = mysql_connect(DB_HOST, DB_USERNAME, DB_DATABASE, DB_PASSWORD);
if(isset($_POST['submit'])) {
$title = $_POST["title"];
$authors = $_POST["authors"];
$description = $_POST["description"];
$price = $_POST["price"];
$file = $_FILES ['image']['tmp_name'];
$file2 = $_FILES ['content']['tmp_name'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$content = addslashes(file_get_contents($_FILES['content']['tmp_name']));
$sql = "INSERT INTO books2 VALUES ('$title', '$authors', '$description', '$price',
'$image','$content') ";
$r = mysql_query($sql, $conn);
if($r)
{
echo "<p>Thank you for entering this book!</p>";
}
}