Friday 22 December 2017

From php a Mysql connection error when using parameters in phpdao2.6

itemprop="text">


I've been using href="http://phpdao.com/" rel="nofollow">phpdao2.6 on a local Mac MAMP
installation and another remote red hat linux server fine. I've recently moved to an EC2
amazon ubuntu flavour and installed a LAMP set
up.



Suddenly I've found I'm getting mysql
connection errors, but not
always:



[09-Jul-2013 21:09:11
Australia/Sydney] PHP Warning: mysql_real_escape_string(): Access denied for user
'ec2-user'@'localhost' (using password: NO) in
/var/www/html/mycobber/class/sql/SqlQuery.class.php on line
40

[09-Jul-2013 21:09:11 Australia/Sydney] PHP Warning:
mysql_real_escape_string(): A link to the server could not be established in
/var/www/html/mycobber/class/sql/SqlQuery.class.php on line
40


I only get these
errors on functions in the MyObjectMySqlExtDAO.class.php if I'm using the




$sql .= 'and
ca.enabled = ? ';

.....

$sqlQuery = new
SqlQuery($sql);

$sqlQuery ->
set('Y');



style
syntax. If I change this syntax to
..



$sql .= " and ca.enabled = 'Y'
";


It works fine. I'm
at a loss to understand why this is happening and I don't want to use the second method
as the input is not sanitized.



I suspect the
issue is a php setting of some kind.



On the EC2
instance I'm
using:




php:
5.3.26
apache: Apache/2.2.24
(Amazon)


My local MAMP
setup is



php:
5.4.10
apache: Apache/2.2.23 (Unix)




Any ideas
out there?


itemprop="text">
class="normal">Answer



The
solution to this issue was to include the connection as the second parameter to the
mysql_real_escape_string function. Looks like on the EC2 ubuntu instance it didn't like
it without
this.



mysql_real_escape_string($string,
$resource)


href="http://php.net/manual/en/function.mysql-real-escape-string.php"
rel="nofollow">http://php.net/manual/en/function.mysql-real-escape-string.php



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...