Php Mysql Error Report
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site how to print mysql error in php About Us Learn more about Stack Overflow the company Business Learn more about php mysqli error hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join php mysql error handling the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up how to display MySql error or die mysql error in php up vote 14 down vote favorite In PHP, I am trying to execute a long MySql query that depends on the user input. However, my query fails with the following message, "Query Failed". Actually I have printed this message whenever the query fails but I am having hard time looking for the reason behind this failure. Unfortunately, I couldn't find it because the
Mysql_query Error
error is not specified on the web page. My question is, is there any way to display the error message that caused the failure on the web page. Thank you. Here's my code, $from= "Findings"; $where=""; if($service!= null) { $from = $from . ", ServiceType_Lookup"; $where= "Findings.ServiceType_ID= ServiceType_Lookup.ServiceType_ID AND ServiceType_Name= ". $service; if($keyword!= null) $where= $where . " AND "; } if( $keyword != null) { $where= $where . "Finding_ID LIKE '%$keyword%' OR ServiceType_ID LIKE '%$keyword%' OR Title LIKE '%$keyword%' OR RootCause_ID LIKE '%$keyword%' OR RiskRating_ID LIKE '%$keyword%' OR Impact_ID LIKE '%$keyword%' OR Efforts_ID LIKE '%$keyword%' OR Likelihood_ID LIKE '%$keyword%' OR Finding LIKE '%$keyword%' OR Implication LIKE '%$keyword%' OR Recommendation LIKE '%$keyword%' OR Report_ID LIKE '%$keyword%'"; } $query = "SELECT Finding_ID, ServiceType_ID, Title, RootCause_ID, RiskRating_ID, Impact_ID, Efforts_ID, Likelihood_ID, Finding, Implication, Recommendation, Report_ID FROM ".$from . " WHERE " . $where; echo "wala 2eshiq"; $this->result = $this->db_link->query($query); if (!$this->result) { printf("Query failed: %s\n", mysqli_connect_error()); exit; } $r = mysqli_query($this->db_link, $query); if($r==false) printf("error: %s\n", mysqli_errno($this->db_link)); php mysql share|improve this question asked Sep 1 '12 at 12:16 Traveling Salesman 56131640 You can just use: $this->db_link->error to get the last error message. For all errors use $this->db_link
Learn Bootstrap Learn Graphics Learn Icons Learn How To JavaScript Learn JavaScript Learn jQuery Learn jQueryMobile Learn AppML Learn AngularJS Learn JSON Learn AJAX Server Side Learn SQL Learn PHP Learn ASP Web Building Web Templates Web
Die(mysql_error())
Statistics Web Certificates XML Learn XML Learn XML AJAX Learn XML DOM Learn XML mysqli_query error DTD Learn XML Schema Learn XSLT Learn XPath Learn XQuery × HTML HTML Tag Reference HTML Event Reference HTML Color Reference mysql get last error HTML Attribute Reference HTML Canvas Reference HTML SVG Reference Google Maps Reference CSS CSS Reference CSS Selector Reference W3.CSS Reference Bootstrap Reference Icon Reference JavaScript JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference AngularJS http://stackoverflow.com/questions/12227626/how-to-display-mysql-error-in-php Reference XML XML Reference XML Http Reference XSLT Reference XML Schema Reference Charsets HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8 Server Side PHP Reference SQL Reference ASP Reference × HTML/CSS HTML Examples CSS Examples W3.CSS Examples Bootstrap Examples JavaScript JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples XML XML Examples XSLT Examples XPath Examples XML Schema Examples http://www.w3schools.com/php/func_mysqli_error.asp SVG Examples Server Side PHP Examples ASP Examples Quizzes HTML Quiz CSS Quiz JavaScript Quiz Bootstrap Quiz jQuery Quiz PHP Quiz SQL Quiz XML Quiz × PHP Tutorial PHP HOME PHP Intro PHP Install PHP Syntax PHP Variables PHP Echo / Print PHP Data Types PHP Strings PHP Constants PHP Operators PHP If...Else...Elseif PHP Switch PHP While Loops PHP For Loops PHP Functions PHP Arrays PHP Sorting Arrays PHP Superglobals PHP Forms PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete PHP Advanced PHP Arrays Multi PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File Upload PHP Cookies PHP Sessions PHP Filters PHP Filters Advanced PHP Error Handling PHP Exception MySQL Database MySQL Database MySQL Connect MySQL Create DB MySQL Create Table MySQL Insert Data MySQL Get Last ID MySQL Insert Multiple MySQL Prepared MySQL Select Data MySQL Delete Data MySQL Update Data MySQL Limit Data PHP - XML PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM PHP - AJAX AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader AJAX Poll PHP Examples PHP Examples PHP Quiz PHP Certificate PHP Reference PHP Array PH
3 Connecting to a MySQL database from PHP 4 The 12 Days of PHP 5 10 Cool Things To Do With PHP About.com http://php.about.com/od/phpwithmysql/f/mysql_error.htm About Tech PHP/MySQL PHP with MySQL How can report MySQL errors into PHP? Robert Daly/OJO Images/Getty Images By Angela Bradley PHP/MySQL Expert Share Pin Tweet Submit Stumble Post Share By Angela Bradley Question: How can report MySQL errors into PHP?How can I receive feedback from MySQL when my PHP encounters a problem?Answer: When you are working with PHP and mysql error MySQL and encounter an error, it is helpful to receive more detailed information regarding the problem to point you in the direction of fixing it. You can use the mysql_error ( ) to get feedback from MySQL to your PHP document if you are encountering problems. It is phrased as: mysql_error ( [link_identifier] )Here are some examples of php mysql error how to utilize mysql_error ()mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) This will return an error if there is a problem connecting to your MySQL database $value = mysql_query($your_query) or die("A MySQL error has occurred.
Your Query: " . $your_query . "
Error: (" . mysql_errno() . ") " . mysql_error()) When you encounter an error, this will return your custom message (A MySQL error has occurred.
) followed by a line number, and the actual error. Show Full Article Related How to close your MySQL connection from PHP Do you know how to close a MySQL connection? MySQL Connect Files in PHP How to Connect PHP Files to a MySQL Database More from the Web Powered By ZergNet Sign Up for Our Free Newsletters Thanks, You're in! About Today Electronics & Gadgets PHP/MySQL You might also enjoy: Healthy Eating Health Tip of the Day Sign up There was an error. Please try again. Please select a newsletter. Please enter a valid email address. Did you mean ? Thank you,,for signing up! PHP/MySQL Learn PHP