[PHP] MySQL Problem with PHP

2002-06-26 Thread BB

I am using PHP and MySQL on a 2k dev box to be uploaded to a linux box

I have a piece of SQL

INSERT INTO `contracts` (`key`, `content`) VALUES (1,'blah blah blah
character 39 is a single speach mark '+CHAR(39)+' blah blah blah')

Instead of inserting: 'blah blah blah character 39 is a single speach mark '
blah blah blah
It inserts 0
All variations work fine when there is no single speachies

help?



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




RE: [PHP] MySQL Problem with PHP

2002-06-26 Thread John Holmes

 INSERT INTO `contracts` (`key`, `content`) VALUES (1,'blah blah blah
 character 39 is a single speach mark '+CHAR(39)+' blah blah blah')

That's because you are adding strings together, not concatenating them
(this isn't javascript!)

Use CONCAT() in MySQL to join strings together. 

mysql select 'this'+char(39)+'that';
++
| 'this'+char(39)+'that' |
++
|  0 |
++
1 row in set (0.03 sec)

mysql select concat('this',char(39),'that');
++
| concat('this',char(39),'that') |
++
| this'that  |
++
1 row in set (0.01 sec)

---John Holmes...


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




Re: [PHP] MySQL Problem with PHP

2002-06-26 Thread BB

I understand about the concat function, but that doesn't really fit into my
scheme of things

I run all text for the web through a function SafeSQL so that values from
the web don't make SQL error or potential hacks occur.

All SafeSQL was doing (for mssql, access and just about any other db) was
$text = preg_replace(/\'/,' + CHAR(39) + ',$text) so when SQL added the
rows with a value of 0 instead of the string I was baffled.

Shame mysql doesn't support inline concatenation

John Holmes [EMAIL PROTECTED] wrote in message
000701c21d14$fc054370$b402a8c0@mango">news:000701c21d14$fc054370$b402a8c0@mango...
  INSERT INTO `contracts` (`key`, `content`) VALUES (1,'blah blah blah
  character 39 is a single speach mark '+CHAR(39)+' blah blah blah')

 That's because you are adding strings together, not concatenating them
 (this isn't javascript!)

 Use CONCAT() in MySQL to join strings together.

 mysql select 'this'+char(39)+'that';
 ++
 | 'this'+char(39)+'that' |
 ++
 |  0 |
 ++
 1 row in set (0.03 sec)

 mysql select concat('this',char(39),'that');
 ++
 | concat('this',char(39),'that') |
 ++
 | this'that  |
 ++
 1 row in set (0.01 sec)

 ---John Holmes...




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