LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 07:12 AM   #1
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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, 08: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, 08:54 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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, 03:48 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,449

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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, 06:24 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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, 07:27 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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 12:59 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 03:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 AM.

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
Open Source Consulting | Domain Registration