简体   繁体   English

简单的MySQL查询无法正常工作

[英]Simple MySQL query won't work

I'm trying to run this simple php script from browser but it won't work. 我正在尝试从浏览器运行此简单的php脚本,但是它将无法正常工作。 It seems that it connects to database but can't complete mysql query. 似乎它已连接到数据库,但无法完成mysql查询。 Anyway this query works fine from PhpMyAdmin. 无论如何,此查询可以从PhpMyAdmin正常工作。 What seems to be a problem? 似乎有什么问题?

<?php
// DB
$DB_HOSTNAME = "localhost";
$DB_USERNAME = "********";
$DB_PASSWORD = "********";
$DB_DATABASE = "vladbl0m_eshop";

// Create connection
$con=mysqli_connect($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE); 

// Check connection
 if (mysqli_connect_errno($con))   {
echo "Failed to connect to MySQL:" . mysqli_connect_error();   
 }
else echo "CONNECTED TO " . $DB_DATABASE;

// mySQL query

// execute the query.
$result = $link->query("INSERT INTO oc_test SET text ='12345'") or die("Error in the consult.." . mysqli_error($link));

?>

There is no $link defined anywhere... use $con instead of that. 在任何地方都没有定义$link ...使用$con代替它。

Replace the $link with $con and see what you are doing it wrong , since you mapped the connection wrongly , you are not able to see the proper errors. $link替换为$link $con ,看看您在做什么错了,因为您错误地映射了连接,所以您看不到正确的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM