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