LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-15-2008, 08:12 AM   #1
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
[php and mysql]mysql warnings


I've spent a couple of hours yesterday fixing where mydate>'2008-04-14 24:00' in a select query in a php script.

Only after I ran it in the normal mysql client, I saw that there was a warning about an incorrect date/time format.

So is it possible to retrieve MySql warnings using php ?
 
Old 04-15-2008, 09:50 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
If you are using mysqli, then the mysqli_warning_count() function will tell you how many warning you have. You can then retrieve them using the SQL call SHOW WARNINGS. Check out the PHP manual for more details.
 
Old 04-15-2008, 09:54 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
I don't use mysqli, but will have a look at an query with show warnings and see if I can use it with normal mysql.

Thanks a lot for the reply.
 
Old 04-16-2008, 04:48 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,159

Rep: Reputation: 258Reputation: 258Reputation: 258
Hi

From php.ini (in the MySql section):

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off
 
Old 04-16-2008, 07:24 AM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Not about the error message but about the error itself: 24:00 is not a valid time in MySQL. Although it should be, because it 2008-04-15 24:00 is the second after 2008-04-15 23:59.

After one full year developing a project which does a lot of date/time handling I found that it is generally better to do everything in Unix timestamps. That saves a lot of juggling between time/date and timestamps in PHP as well. Only for presentation one should use time/date, which is easy in PHP (gmtime and friends) and in MySQL any timestamp can be shown human readable as FROM_UNIXTIME(ts).

But that doesn't answer your original question, does it?

jlinkels
 
Old 04-16-2008, 08:27 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
@jlinkels:
I expected the 24 to be the problem and running part of the query in the mysql client confirmed that. But it took me a while.

As I'm doing an update on an existing LAMP solution (that I wrote about 1.5 year ago) so it's a bit late to change the full design of my LAMP solution over to unix_timestamps. But I will definitely keep it in mind for the next application that I need to write.

@Guttorm:
thanks for that tip
 
  


Reply

Tags
mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql works from command line, but mysql.sock (13) error from php.. leif_84 Linux - Server 0 07-23-2007 01:59 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 04:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 09:44 AM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 03:54 PM


All times are GMT -5. The time now is 04:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration