PHP mysql_fetch_assoc()mysql_query()错误

时间:2018-12-02 21:36:46

标签: php mysql mysqli pdo

我使用此代码在我的网站上本地计算“访问者”,但是该代码不起作用。

我连接到我的MySQL服务器和数据库,但是在mysql_fetch_assoc()mysql_query()上出现错误。


下面是代码:

<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
try
{
    $conn = new PDO("mysql:host=$servername;dbname=simplecounter", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
}
catch(PDOException $e)
{
    echo "Connection failed: " . $e->getMessage();
}
$find_counts = mysql_query("SELECT * FROM user_count");//#here
while($row = mysql_fetch_assoc($find_counts))//#here
{
    $current_counts = $row ['counts'];
    $new_count = $current_counts + 1;
    $update_count = mysql_query("UPDATE `simplecounter` . `user_count` SET counts = $new_count ");
}
?>

我该如何解决?

0 个答案:

没有答案