php 先行編譯查詢始終fetch不到資料

來源:互聯網
上載者:User
php prepare fetch

include ('../db/MySqlConnect.php');$conn = new MySqlConnect();$mysqli = $conn->getConnection();$sql = 'select id, username, password from admin where id = ?';$seach_id = 1;settype($seach_id, "integer");if($stmt = $mysqli->prepare($sql)) {$stmt->bind_param('i', $seach_id);$stmt->execute();$stmt->bind_result($rs_id, $rs_name, $rs_password);if($stmt->fetch() == NULL) {echo 'no result';} else { printf('id:%s, name:%s, password:%s 
', $rs_id, $rs_name, $rs_password);}$stmt->close();$mysqli->close();}

SQL語句明明可以查詢出來資料, 我使用PHP的非先行編譯語句($result = $mysqli->query($query);)也可以查詢出來記錄, 就是上面的查詢代碼始終在fetch出抓取不到資料,我的PHP版本是php-5.2.5-x64, 環境是64位的Win7, 有遇到過的朋友或知道的能給分析一下麼, 我已經困擾2天了....謝謝了


回複討論(解決方案)

代碼看上去沒有問題
但如果直接複製你的代碼就無法通過語法檢查

http://www.php.net/manual/en/mysqli.prepare.php

http://xiaobo-liu.iteye.com/blog/1288008

settype($seach_id, "integer");
可以省略

什麼輸出都沒有?先確認進入if了沒有?

可能是自己機器某些地方的配置有問題, 最後決定啟用PDO了, 反正早晚都需要學習新知識
而且PDO確實要比MySQli 要好, 這個問題就算解決了吧
PDO用熟練了很方便, 而且PDO的prepare 就沒有上面的問題, 應該是自己配置的問題

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.