PHP database query error

Source: Internet
Author: User
PHP database query error, PHPcodedefine (& quot; MYSQL_SERVER_NAME & quot;, & quot; localhost & quot;); define (& quot; MYSQL_USERNAME & quot;, & quot; root & quot;); define PHP database query error,
PHP code
  Define ("MYSQL_SERVER_NAME", "localhost"); define ("MYSQL_USERNAME", "root"); define ("MYSQL_PASSWORD", ""); define ("MYSQL_DATABASE ", "test"); define ("TABLE_NAME", "voicemail"); // connect to the database server address, user name, password $ conn = mysql_connect (MYSQL_SERVER_NAME, MYSQL_USERNAME, MYSQL_PASSWORD) or die ("Sorry, cocould not connect to MySQL server! "); // Select database mysql_select_db (MYSQL_DATABASE, $ conn) or die (" select database fial! "); // Php should pay attention to injection prevention // add the backslash $ uniqueid = addslashes ($ uniqueid) in [single quotes, double quotes, backslash, NULL ); $ SQL = "select * from ". TABLE_NAME. "where uniqueid = '$ uniqueid'"; echo $ SQL; // obtain the result set $ result = mysql_query ($ SQL) or die ("SQL query fail "); // cursor while ($ row = mysql_fetch_row ($ result) {echo $ row ["billsec"] ;}// close the connection mysql_close ();


Why did he or die when querying? ----- SQL query fail?
How can we know what is wrong?
I am a beginner. Thank you.


------ Solution --------------------
As I said, PHP is the best language. echo mysql_error () directly; better than anything else.
Don't you think java exception capture is annoying?
------ Solution --------------------
1. I hope to use php as a java framework.
2. Yes, php manual on the php.net website is a page that every Php programmer should keep open at any time and search for any problems. For example, you want to find a preparestatment automatic anti-injection function, because this is mysql-related, so search: mysql, find useful information in it to get this page: http://cn2.php.net/manual/zh/mysqli.prepare.php, that is, mysqli, I indicates the enhanced version of mysql.
3. if you use a framework, you can choose the simplest one.
4, yes, directly in the class static $ I = xxx;, the access is also ClassName: $ I.
5. when a request runs a script, all processes are destroyed, so don't worry.
6. no bottlenecks
7. related to programmers and languages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.