Re: [PHP-DB] Re: PDO Mysql data truncation missing error

2012-08-21 Thread Karl DeSaulniers


On Aug 21, 2012, at 3:44 PM, Matt Pelmear wrote:


Amit,

Thanks for the suggestion. Unfortunately, even when I explicitly  
enable E_WARNING or even E_ALL error reporting in php I still do not  
receive any indication that data was truncated on insert.


-Matt

On 08/21/2012 07:09 AM, Amit Tandon wrote:


Dear Matt,

Even with MySQL, u get the warning as the show warnings is enabled.  
With php bound scripts, you have to check warnings  to see the  
warnings. However, php is quite flexible and you an use  
error_reporting(E_WARNING) for non-fatal error reporting


regds
amit

On Aug 21, 2012 10:41 AM, "Matt Pelmear" mailto:mjpelm...@gmail.com 
>> wrote:


   On 08/21/2012 01:08 AM, David Robley wrote:

   Matt Pelmear wrote:

   Hello,

   I'm trying to detect data truncation on insert to MySQL
   using PDO.

   As far as I can tell, this gets reported at least in some
   cases (ex:
   http://drupal.org/node/1528628), but I have been unable to
   see this
   myself.

   The test table I'm using has a column that is VARCHAR(5):

   mysql>  describe test;
   +---+--+--+-+- 
+---+
   | Field | Type | Null | Key | Default |  
Extra |
   +---+--+--+-+- 
+---+
   | id| int(10) unsigned | YES  | | NULL 
|   |
   | data  | varchar(5)   | YES  | | NULL 
|   |
   +---+--+--+-+- 
+---+

   2 rows in set (0.00 sec)


   My test script inserts a ten character string into the 5
   character column:

    PHP TEST CODE 

   $pdo = new PDO(
 'mysql:host=localhost;dbname=test',
 'username',
 'password'
   );

   $pdo->setAttribute(PDO::ATTR_ERRMODE,  
PDO::ERRMODE_EXCEPTION);


   $retval = $pdo->query( 'INSERT INTO `test` (data) VALUES
   ("1234567890")'
   );

   print_r( $retval );

    END TEST CODE 

   This results in a new row in the `test` table, truncated
   after the 5th
   character as expected, but the truncation is not reported.
   (running in
   php 5.3.2 and 5.3.4)
   Running the same query directly in the mysql command line
   shows a
   warning as expected.

   Am I missing something simple here?

   Thanks,
   Matt

   Caveat: I don't use PDO but maybe the PDO::ERRMODE_WARNING
   attribute may do
   what you want?



   Cheers


   Interesting idea. I gave it a try, but got the same result!
   I think PDO::ERRMODE_WARNING tells PDO to give PHP warnings versus
   throw exceptions when there are problems (if I'm understanding it
   properly).

   -Matt

   -- PHP Database Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php





Forgive me if I am off, but why would you check to see if a string is  
truncated in your database?
Wouldn't you just check to make sure a string is a certain length in  
PHP first and then instert it into the database?

Then you know for sure that nothing is getting truncated?

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: PDO Mysql data truncation missing error

2012-08-21 Thread Bastien Koert
On Tue, Aug 21, 2012 at 4:44 PM, Matt Pelmear  wrote:
> Amit,
>
> Thanks for the suggestion. Unfortunately, even when I explicitly enable
> E_WARNING or even E_ALL error reporting in php I still do not receive any
> indication that data was truncated on insert.
>
> -Matt
>
>
> On 08/21/2012 07:09 AM, Amit Tandon wrote:
>>
>>
>> Dear Matt,
>>
>> Even with MySQL, u get the warning as the show warnings is enabled. With
>> php bound scripts, you have to check warnings  to see the warnings. However,
>> php is quite flexible and you an use error_reporting(E_WARNING) for
>> non-fatal error reporting
>>
>> regds
>> amit
>>
>> On Aug 21, 2012 10:41 AM, "Matt Pelmear" > > wrote:
>>
>> On 08/21/2012 01:08 AM, David Robley wrote:
>>
>> Matt Pelmear wrote:
>>
>> Hello,
>>
>> I'm trying to detect data truncation on insert to MySQL
>> using PDO.
>>
>> As far as I can tell, this gets reported at least in some
>> cases (ex:
>> http://drupal.org/node/1528628), but I have been unable to
>>
>> see this
>> myself.
>>
>> The test table I'm using has a column that is VARCHAR(5):
>>
>> mysql>  describe test;
>> +---+--+--+-+-+---+
>>
>> | Field | Type | Null | Key | Default | Extra |
>> +---+--+--+-+-+---+
>>
>> | id| int(10) unsigned | YES  | | NULL|   |
>> | data  | varchar(5)   | YES  | | NULL|   |
>> +---+--+--+-+-+---+
>>
>> 2 rows in set (0.00 sec)
>>
>>
>> My test script inserts a ten character string into the 5
>> character column:
>>
>>  PHP TEST CODE 
>>
>> $pdo = new PDO(
>>   'mysql:host=localhost;dbname=test',
>>   'username',
>>   'password'
>> );
>>
>> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>>
>>
>> $retval = $pdo->query( 'INSERT INTO `test` (data) VALUES
>> ("1234567890")'
>> );
>>
>> print_r( $retval );
>>
>>  END TEST CODE 
>>
>> This results in a new row in the `test` table, truncated
>> after the 5th
>> character as expected, but the truncation is not reported.
>> (running in
>> php 5.3.2 and 5.3.4)
>> Running the same query directly in the mysql command line
>> shows a
>> warning as expected.
>>
>> Am I missing something simple here?
>>
>> Thanks,
>> Matt
>>
>> Caveat: I don't use PDO but maybe the PDO::ERRMODE_WARNING
>> attribute may do
>> what you want?
>>
>>
>>
>> Cheers
>>
>>
>> Interesting idea. I gave it a try, but got the same result!
>> I think PDO::ERRMODE_WARNING tells PDO to give PHP warnings versus
>> throw exceptions when there are problems (if I'm understanding it
>> properly).
>>
>> -Matt
>>
>> -- PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>


MySQL will silently truncate it without throwing an error, unless
you've looked into enabling alternate behavior. Set
STRICT_TRANS_TABLES (for InnoDB) or STRICT_ALL_TABLES (for any storage
engine) in MySQL's config and it'll throw the following error instead
of silently truncating data:
[Err] 1406 - Data too long for column '[some column]' at row [XYZ]
Does that help?
-- 

Bastien

Cat, the other other white meat

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: PDO Mysql data truncation missing error

2012-08-21 Thread Matt Pelmear

Amit,

Thanks for the suggestion. Unfortunately, even when I explicitly enable 
E_WARNING or even E_ALL error reporting in php I still do not receive 
any indication that data was truncated on insert.


-Matt

On 08/21/2012 07:09 AM, Amit Tandon wrote:


Dear Matt,

Even with MySQL, u get the warning as the show warnings is enabled. 
With php bound scripts, you have to check warnings  to see the 
warnings. However, php is quite flexible and you an use 
error_reporting(E_WARNING) for non-fatal error reporting


regds
amit

On Aug 21, 2012 10:41 AM, "Matt Pelmear" > wrote:


On 08/21/2012 01:08 AM, David Robley wrote:

Matt Pelmear wrote:

Hello,

I'm trying to detect data truncation on insert to MySQL
using PDO.

As far as I can tell, this gets reported at least in some
cases (ex:
http://drupal.org/node/1528628), but I have been unable to
see this
myself.

The test table I'm using has a column that is VARCHAR(5):

mysql>  describe test;
+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| id| int(10) unsigned | YES  | | NULL|   |
| data  | varchar(5)   | YES  | | NULL|   |
+---+--+--+-+-+---+
2 rows in set (0.00 sec)


My test script inserts a ten character string into the 5
character column:

 PHP TEST CODE 

$pdo = new PDO(
  'mysql:host=localhost;dbname=test',
  'username',
  'password'
);

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$retval = $pdo->query( 'INSERT INTO `test` (data) VALUES
("1234567890")'
);

print_r( $retval );

 END TEST CODE 

This results in a new row in the `test` table, truncated
after the 5th
character as expected, but the truncation is not reported.
(running in
php 5.3.2 and 5.3.4)
Running the same query directly in the mysql command line
shows a
warning as expected.

Am I missing something simple here?

Thanks,
Matt

Caveat: I don't use PDO but maybe the PDO::ERRMODE_WARNING
attribute may do
what you want?



Cheers


Interesting idea. I gave it a try, but got the same result!
I think PDO::ERRMODE_WARNING tells PDO to give PHP warnings versus
throw exceptions when there are problems (if I'm understanding it
properly).

-Matt

-- 
PHP Database Mailing List (http://www.php.net/)

To unsubscribe, visit: http://www.php.net/unsub.php





[PHP-DB] Nubbie pointers on MySQL users ...

2012-08-21 Thread Lester Caine

OK

I've had a crash course in MySQL and have moved some joomla sites over to one of 
my servers. I've got phpmyadmin up and running and can see one of the remote 
servers, and I have a mirror running on a local server, but I'm a little 
confused over 'user names'


The local machine (php5.3) worked quite happily with user@localhost, but when I 
tried the same setup on the second machine (php5.4) while I could get into the 
server with 'localhost' in order to get PHP connecting I ended up with a 
combination of the domain name 'medw.org.uk' and the local machine name 'rdm2' 
with the same user names. Where am I going wrong? Is there something I'm missing 
setup wise?


( And I don't know who you manage with raw SQL for transfers, on Firebird I can 
backup and restore a 500Mb database in seconds ;) )


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] ANN: PHP Generator 12.8 released

2012-08-21 Thread SQL Maestro Group

Hi!

SQL Maestro Group is happy to announce the release of PHP Generator 12.8, a
family of GUI frontends that allow you to generate feature-rich CRUD web
applications for your databases. There are versions for MySQL, MS SQL
Server, PostgreSQL, Oracle, SQLite, Firebird, DB2, SQL Anywhere and MaxDB.
http://www.sqlmaestro.com/news/company/php_generators_updated_to_12_8/

Online demo:
http://demo.sqlmaestro.com/

PHP Generator comes in both Freeware and Professional editions. The feature
matrix can be found at
http://www.sqlmaestro.com/products/mysql/phpgenerator/feature_matrix/

Please note that before Sep 2 you can purchase Professional Edition of any
PHP Generator as well as all other our products and bundles with a 20%
discount.

Top 10 new features
===

1. New modern look and feel.
2. Enhanced master-detail management.
3. Custom templates.
4. Automatic Filter Row.
5. Filter Builder.
6. New visual themes.
7. Improved usability.
8. New Autocomplete and Milti-Level Autocomplete controls.
9. New "after action" events.
10. On-the-fly metadata refreshing.

Full press-release (with explaining screenshots) is available at:
http://www.sqlmaestro.com/news/company/php_generators_updated_to_12_8/

Background information:
---
SQL Maestro Group offers complete database admin, development and management
tools for MySQL, SQL Server, PostgreSQL, Oracle, DB2, SQLite, SQL Anywhere,
Firebird and MaxDB providing the highest performance, scalability and
reliability to meet the requirements of today's database applications.

Sincerely yours,
The SQL Maestro Group Team
http://www.sqlmaestro.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] echo into variable or the like

2012-08-21 Thread Daniel Brown
On Tue, Aug 21, 2012 at 12:01 AM,   wrote:
> Hi, this is my first post so forgive me if I missed a rule and do something 
> wrong.
>
> I have this code,
>
> echo $_SERVER['PHP_SELF']."?";
> foreach ($_GET as $urlvar=>$urlval)
> echo $urlvar."=".$urlval."&";
>
> It works by it’s self.
> I want to insert the output in a table.  Is there a way to ‘echo’ into a 
> variable(i.e. make the output of this echo the value of a variable) or am I 
> on the wrong track all together?

This question actually belongs on the PHP General mailing list.

As for echoing into a variable, the only way that's really
possible is with output buffering (ob_start(), ob_get_contents(),
ob_end_clean(), et al).  However, you don't need (and shouldn't want)
to do this here.  Instead, as your snippet really won't do much of
anything useful, you should (entirely) rewrite your code to look
something like this, for an HTML table:

'.PHP_EOL;
foreach ($_GET as $key => $value) {
echo ' '.PHP_EOL;
echo '  '.$key.''.PHP_EOL;
echo '  '.$value.''.PHP_EOL;
echo ' '.PHP_EOL;
}
echo '';
?>

However, since it looks almost as if you're trying to build a
query string based upon the supplied GET variables, you may want to
try looking into http_build_query().

-- 

Network Infrastructure Manager
http://www.php.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: PDO Mysql data truncation missing error

2012-08-21 Thread Amit Tandon
Dear Matt,

Even with MySQL, u get the warning as the show warnings is enabled. With
php bound scripts, you have to check warnings  to see the warnings.
However, php is quite flexible and you an use error_reporting(E_WARNING)
for non-fatal error reporting

regds
amit
On Aug 21, 2012 10:41 AM, "Matt Pelmear"  wrote:

> On 08/21/2012 01:08 AM, David Robley wrote:
>
>> Matt Pelmear wrote:
>>
>>  Hello,
>>>
>>> I'm trying to detect data truncation on insert to MySQL using PDO.
>>>
>>> As far as I can tell, this gets reported at least in some cases (ex:
>>> http://drupal.org/node/1528628**), but I have been unable to see this
>>> myself.
>>>
>>> The test table I'm using has a column that is VARCHAR(5):
>>>
>>> mysql>  describe test;
>>> +---+--+--**+-+-+---+
>>> | Field | Type | Null | Key | Default | Extra |
>>> +---+--+--**+-+-+---+
>>> | id| int(10) unsigned | YES  | | NULL|   |
>>> | data  | varchar(5)   | YES  | | NULL|   |
>>> +---+--+--**+-+-+---+
>>> 2 rows in set (0.00 sec)
>>>
>>>
>>> My test script inserts a ten character string into the 5 character
>>> column:
>>>
>>>  PHP TEST CODE 
>>>
>>> $pdo = new PDO(
>>>   'mysql:host=localhost;dbname=**test',
>>>   'username',
>>>   'password'
>>> );
>>>
>>> $pdo->setAttribute(PDO::ATTR_**ERRMODE, PDO::ERRMODE_EXCEPTION);
>>>
>>> $retval = $pdo->query( 'INSERT INTO `test` (data) VALUES ("1234567890")'
>>> );
>>>
>>> print_r( $retval );
>>>
>>>  END TEST CODE 
>>>
>>> This results in a new row in the `test` table, truncated after the 5th
>>> character as expected, but the truncation is not reported. (running in
>>> php 5.3.2 and 5.3.4)
>>> Running the same query directly in the mysql command line shows a
>>> warning as expected.
>>>
>>> Am I missing something simple here?
>>>
>>> Thanks,
>>> Matt
>>>
>> Caveat: I don't use PDO but maybe the PDO::ERRMODE_WARNING attribute may
>> do
>> what you want?
>>
>>
>>
>> Cheers
>>
>
> Interesting idea. I gave it a try, but got the same result!
> I think PDO::ERRMODE_WARNING tells PDO to give PHP warnings versus throw
> exceptions when there are problems (if I'm understanding it properly).
>
> -Matt
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>