PHP PDO串連mysql失敗

來源:互聯網
上載者:User
在conn.php中用pdo串連本地的mysql資料庫, 但php網頁提交的資料在mysql裡面沒有存入, 但是運行conn.php不報錯, 不知道到底是哪裡有問題!! 糾結了三天了!!拜託各位看看

 "SET NAMES utf8"));} catch ( Exception $e ) {  echo "Connection à MySQL impossible : ", $e->getMessage();  die();}?>


回複討論(解決方案)

你這隻是串連
你是怎麼用的呢?

你這隻是串連
你是怎麼用的呢?



最主要的是寫了這個函數
  public function insertR(){            global $connection;            $sql=$connection->prepare("insert into reponse SET MSISDN=:ref_clt,Q1=:r1,Q2=:r2,Q3=:r3,Q4=:r4,Q5=:r5,Q6=:r6,Q6b=:r6c,Q7=:r7,Q8=:r8,Date_Reponse=:date,Type_Commande=:type,Host_Reponse=:host,Ip_Reponse=:ip,semaine_reponse=:sem") or die (mysql_error());            $sql->bindValue('ref_clt',$this->MSISDN);            $sql->bindValue('r1',$this->Q1);            $sql->bindValue('r2',$this->Q2);             $sql->bindValue('r3',$this->Q3);            $sql->bindValue('r4',$this->Q4);             $sql->bindValue('r5',$this->Q5);            $sql->bindValue('r6',$this->Q6);            $sql->bindValue('r6c',$this->Q6b);             $sql->bindValue('r7',$this->Q7);            $sql->bindValue('r8',$this->Q8);            $sql->bindValue('date',$this->date);            $sql->bindValue('type',$this->type);            $sql->bindValue('host',$this->hostname);            $sql->bindValue('ip',$this->ip);            $sql->bindValue('sem',$this->sem);            $sql->execute();           //var_dump($sql);                            }


但是代碼應該是沒有問題的, 是上一個人寫好並且測試過成功的,然後我拷貝到我的電腦裡並且用phpmyadmin建立了一個一樣資料庫, 但我的就沒有辦法存入

http://www.w3cschool.cc/php/pdo-errorinfo.html
用這可以檢查mysql error,試試看吧

看看錯誤記錄檔。

各位大神,

現在問題變成了 php可以串連本地的mysql, 但是串連不上遠端, 報錯host unknown,
我用cmd ping host id, 是失敗的, 請問要怎麼樣才能串連上?

host unknown也就是找不到host,你是怎麼串連的?ip還是網域名稱。
貼一下。

對不起各位 最後崩潰的發現是因為代碼跟資料庫表格結構不符合。。
立馬給分

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.