简体   繁体   中英

Why SQLSTATE[HY000]: General error?

This is a code to register the head of a group and then his partner(s).

<?
session_start();
require_once('db.php');
$db = new DB();
$db->newHead($_POST['fname'], $_POST['lname'], $_POST['school'], $_POST['day'], $_POST['month'], $_POST['year'], $_POST['email']);
$hId = $db->getId($_POST['email'], 1);
if ($_POST['pnum'] === 1)
{
    $db->newPartner($hId, $_POST['fname1'], $_POST['lname1'], $_POST['day1'], $_POST['month1'], $POST['year1'], $_POST['email1']);
    $pId = getId($_POST['email1'], 0);
    $db->setHeadId($hId, $pId, 1);
}
if ($_POST['pnum'] === 2)
{
    $db->newPartner($hId, $_POST['fname1'], $_POST['lname1'], $_POST['day1'], $_POST['month1'], $POST['year1'], $_POST['email1']);
    $p1Id = getId($_POST['email1'], 0);
    $db->setHeadId($hId, $p1Id, 1);

    $db->newPartner($hId, $_POST['fname2'], $_POST['lname2'], $_POST['day2'], $_POST['month2'], $POST['year2'], $_POST['email2']);
    $p2Id = getId($_POST['email2'], 0);
    $db->setHeadId($hId, $p2Id, 2);
}
header("Location:Register.php");
?>

and this is part of db.php:

    public function getId($email, $type)
{
    if ($type)
        $query = "SELECT * FROM t_head where h_email = '$email';";
    else
        $query = "SELECT * FROM t_partner where p_email = '$email';";
    return $this->query($query);
}

public function newPartner($hId, $fname, $lname, $day, $month, $year, $email)
{
    $query = "INSERT INTO t_partner (p_headid, p_fname, p_lname, p_day, p_month, p_year, p_email)
    VALUES ('$hId', '$fname', '$lname', '$day', '$month', '$year', '$email');";
    return $this->query($query);
}

public function newHead($fname, $lname, $hschool, $day, $month, $year, $email)
{
    $query = "INSERT INTO t_head (h_fname, h_lname, h_school, h_day, h_month, h_year, h_email)
    VALUES('$fname', '$lname', '$hschool', '$day', '$month', '$year', '$email');";
    return $this->query($query);
}

    public function setHeadId($hId, $pId, $num)
    {
        if ($num === 1)
            $query = "UPDATE t_head SET h_p1 = '$pId' WHERE h_id = '$hId';";
        else
            $query = "UPDATE t_head SET h_p2 = '$pId' WHERE h_id = '$hId';";
        $this->execute($query);
    }

What's the problem? DB is class that is worked with PDO. (I don't know what's this! but I always copy it then I write the functions at then bottom of it and it always worked correctly.) But know What does this error mean?

  • Excuse me If I pasted all of the code! I don't know SQLSTATE[HY000]: General error is related to which part, so that I couldn't paste any specific part/func for you.

  • My site copied to another server and the DNS was changed near 3 hours ago for a purpose. If this detail can help you ...

It happened to me something similar a few weeks ago. I fixed it changing the php.ini

I changed

;extension=php_pdo_mysql_mysqlnd.dll
extension=php_pdo_mysql_libmysql.dll

to

extension=php_pdo_mysql_mysqlnd.dll
;extension=php_pdo_mysql_libmysql.dll

basically you change the mysql driver php uses. I used xampplite 1.7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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