第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

關(guān)于mysqli語(yǔ)法的php文件導(dǎo)入錯(cuò)誤

關(guān)于mysqli語(yǔ)法的php文件導(dǎo)入錯(cuò)誤

PHP
Qyouu 2021-06-11 14:08:05
我正在嘗試將文件導(dǎo)入到數(shù)據(jù)庫(kù)中,無論我做了什么更改,我都會(huì)收到相同的錯(cuò)誤。錯(cuò)誤是——您的 SQL 語(yǔ)法有錯(cuò)誤;檢查與您的 MariaDB 服務(wù)器版本相對(duì)應(yīng)的手冊(cè),以獲取在第 1 行的“1”附近使用的正確語(yǔ)法似乎無法找到解決方案。我究竟做錯(cuò)了什么?謝謝 :)<?php$conn = mysqli_connect('localhost','root');if (!$conn) {    die(mysqli_error());} $db = mysqli_query($conn,"CREATE DATABASE IF NOT EXISTS monthly");if (mysqli_query($conn,$db)){    echo "Database created";} else {    echo "Database not created: " . mysqli_error($conn);}mysqli_select_db($conn, "monthly");$ct = mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `month1`(`week1` INT(4) NOT NULL,`week2` INT(4) NOT NULL,`week3` INT(4) NOT NULL,`week4` INT(4) NOT NULL)");if (mysqli_query($conn,$ct)){    echo "Table created";} else {    echo "table not created: " . mysqli_error($conn);}$open = fopen('/xampp/htdocs/month1.txt','r');while (!feof($open)) {    $getTextLine = fgets($open);    $explodeLine = explode(',',$getTextLine, 4);    if(count($explodeLine) !=4) {        continue;    }    $week1 = $explodeLine[0];    $week2 = $explodeLine[1];    $week3 = $explodeLine[2];    $week4 = $explodeLine[3];    list($week1,$week2,$week3,$week4) = $explodeLine;    $qry = "insert into 'month1' ('week1','week2','week3','week4') values('$week1','$week2','$week3','$week4')" or die(mysqli_error());    mysqli_query($conn,$qry);}fclose($open);mysqli_close($conn);?>
查看完整描述

2 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

請(qǐng)參閱添加的評(píng)論以解釋我所做的修改


<?php

// this needs a password, I assume yours in blank

$conn = mysqli_connect('localhost','root', '');


if (!$conn) {

    die(mysqli_error());


// this creates a database

$status = mysqli_query($conn,"CREATE DATABASE IF NOT EXISTS monthly");


if ($status){

    echo "Database created";

} else {

    echo "Database not created: " . mysqli_error($conn);

}


mysqli_select_db($conn, "monthly");


$ct = mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `month1`(

                        `week1` INT(4) NOT NULL,

                        `week2` INT(4) NOT NULL,

                        `week3` INT(4) NOT NULL,

                        `week4` INT(4) NOT NULL

                        )");

if ($ct){

    echo "Table created";

} else {

    echo "table not created: " . mysqli_error($conn);

}


$open = fopen('/xampp/htdocs/month1.txt','r');


while (!feof($open)) 

{

    $getTextLine = fgets($open);

    $explodeLine = explode(',',$getTextLine, 4);


    if(count($explodeLine) !=4) {

        continue;

    }

    $week1 = $explodeLine[0];

    $week2 = $explodeLine[1];

    $week3 = $explodeLine[2];

    $week4 = $explodeLine[3];


    list($week1,$week2,$week3,$week4) = $explodeLine;


    // Column and databse names are wrapped in backticks

    // Text data is wrapped in single quotes

    // integer data CAN be wrapped in single quote, but does not have to be

    $qry = "insert into `month1` (`week1`,`week2`,`week3`,`week4`) 

                        values($week1,$week2,$week3,$week4)" 

    // This is placing a query in a string variable 


    // so this die() is nonsense and anyway it meeds a parameter in the mysqli_error()

    // like this mysqli_error($conn)

    //   or die(mysqli_error());


    // this execues the query above

    mysqli_query($conn,$qry);


    // if you made the above line into 

    // $res = mysqli_query($conn,$qry);

    // you could check if it actually worked like this

    /*

    if ( !$res ) {

        mysqli_error($conn);

    }

    */


}

fclose($open);

mysqli_close($conn);

?>


查看完整回答
反對(duì) 回復(fù) 2021-06-13
?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

我正在更改您代碼上部的幾行,請(qǐng)檢查并比較,有一些小錯(cuò)誤,例如


if (mysqli_query($conn,$db)) and if (mysqli_query($conn,$ct)){ 

 the above lines have no meaning.

請(qǐng)?jiān)谠撐恢没蚰奈恢锰砑右韵麓a。


<?php

$conn = mysqli_connect('localhost','root','');


if (!$conn) {

    die(mysqli_error());


$db = mysqli_query($conn,"CREATE DATABASE IF NOT EXISTS monthly");


if ($db){

    echo "Database created";

} else {

    echo "Database not created: " . mysqli_error($conn);


}


mysqli_select_db($conn, "monthly");


$ct = mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `month1`(

`week1` INT(4) NOT NULL,

`week2` INT(4) NOT NULL,

`week3` INT(4) NOT NULL,

`week4` INT(4) NOT NULL

)");

if ($ct){

    echo "Table created";

} else {

    echo "table not created: " . mysqli_error($conn);


}


查看完整回答
反對(duì) 回復(fù) 2021-06-13
  • 2 回答
  • 0 關(guān)注
  • 174 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)