PHP查询数据库失误

WBOY
Release: 2016-06-13 13:24:09
Original
995 people have browsed it

PHP查询数据库出错、

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->define("MYSQL_SERVER_NAME","localhost");
define("MYSQL_USERNAME","root");
define("MYSQL_PASSWORD","");
define("MYSQL_DATABASE","test");
define("TABLE_NAME","voicemail");


    //连接数据库server地址,用户名,密码
     $conn = mysql_connect(MYSQL_SERVER_NAME,MYSQL_USERNAME,MYSQL_PASSWORD) or die(" Sorry , Could not connect to MySQL server ! ");
     
     //选取database
     mysql_select_db(MYSQL_DATABASE,$conn) or die("select database fial !");
     //php 要注意防注入
     
     //转义在 【单引号、 双引号 、反斜杠、 NULL、】添加反斜杠
     $uniqueid = addslashes($uniqueid);
     $sql = "select  * from ".TABLE_NAME." where uniqueid ='$uniqueid'";
     
     echo $sql; 
     
     //取到结果集
     $result = mysql_query($sql) or die("SQL query fail ");
     
    
        
     //游标
    while($row = mysql_fetch_row($result)){
        echo $row["billsec"];
    }
     
     //关闭连接 
     mysql_close();
Copy after login


query的时候他咋就or die 了 -----SQL query fail?
怎么才能知道是什么错误?
我是个初学者。先谢谢各位啦。


------解决方案--------------------
照我说PHP是最好用的语言了,直接 echo mysql_error(); 比什么都强。
难道你就不觉得java的异常捕获很烦人吗?
------解决方案--------------------
1, 希望将php当java用就挑一个框架去用。
2,有,php.net网站的php manual是每个Php程序员应该随时保持打开状态的页面,有问题就搜。比如你希望找一个preparestatment自动防注入的函数,因为这是mysql相关,所以搜索:mysql,在里面找有用的信息得到这个页面:http://cn2.php.net/manual/zh/mysqli.prepare.php , 也就是mysqli,i表示是mysql的加强版。
3,随便你,框架用谁不是用,会什么用什么,不会就挑一个最简单的
4,有,直接在类内static $i = xxx;,访问也是ClassName::$i。
5,一个请求跑一次脚本,跑完进程都销毁了,不用担心。
6,没有瓶颈
7,与程序员有关,与语言无关
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!