0

I'm refactoring an existing application which is using old methods to connect and interact with a mysql database like mysql_connect() and mysql_fetch_array which had code like:

Update The only output Im getting on the page is the below, which are empty arrays.

Array ( [initial] => Array ( ) [additional] => Array ( ) )

Final update This was an issue with the root user not having access to %. I was getting an error like: The user specified as a definer ('root'@'%') does not exist on output this is fixed by running the command:

grant all on *.* to 'root'@'%' identified by 'password' with grant option;

The reason for converting was using the originally coded use of mysql_connect() (not by me) does not work (as far as I know) with mysql when you have remote connections turned off (which I do).

Why isn't my new code outputting anything? The original code above works in development env. where remote connections is turned off, but not in production.

Thank you.

CodeTalk
  • 3,571
  • 16
  • 57
  • 92
  • Done any debugging, like checking return values from your query calls and whatnot? Your query calls are simply assuming nothing could ever fail. Plus why RECONNECT to the db in your getSKills() method when you've already created a connection as part of your object's constructor? – Marc B Jan 14 '15 at 15:20
  • 1
    Why are you using `sprintf()` around your query? – Jay Blanchard Jan 14 '15 at 15:20
  • this is probably not the cause of your problem, but why do you connect twice to the db in your new class (first in connect(), then in getSkills())? – lp_ Jan 14 '15 at 15:21
  • @lp_ I was trying to get it to work first, then go back and fix it. Ive spent already a lot of time already on this. – CodeTalk Jan 14 '15 at 15:28
  • @JayBlanchard - I've remote this method, but that doesnt fix anything. – CodeTalk Jan 14 '15 at 15:30
  • @MarcB - I have done trying to return values, thats what ive been trying to do most of the time ive spent on it. I have run test code to check for example that $this->dnConn is properly connecting using this: if ($this->dbConn->ping()) { printf ("Our connection is ok!\n");} – CodeTalk Jan 14 '15 at 15:32
  • ah, this is what I thought. I just pointed that out, because when you reconnect to the db, you don't check for errors, so you won't see if it was successful or not and you might mess up the previously active connection. but others already have some more useful recommendations here – lp_ Jan 14 '15 at 15:37
  • @lp_ - ive tried them, without any luck thus far – CodeTalk Jan 14 '15 at 15:40
  • you should really get some error somewhere, but the configuration of the web server may prevent you from seeing it on your page. try to check out the logs that you can access or consider debugging as recommended [here](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) – lp_ Jan 14 '15 at 16:33

1 Answers1

1
  • Your class has a missing closing bracket } at the end.

  • You do not select database

  • Why do you create $this->dbConn everywhere, you defined it in your constructor.

  • Where is your $this->dbConn->query defined? $this->dbConn is a resource of connection.

NOTE

Add error_reporting(E_ALL); and ini_set('display_errors', 1); to catch your errors.

vaso123
  • 12,347
  • 4
  • 34
  • 64
  • I triedthis, but no errors are reported, by putting error_reporting(E_ALL); to the end of the script. I also do select the database in mysqli_connect() . I was using $this->dbConn everywhere to remove the issue from possible further issues that could arise (until I got it to work), then would obviously just use it once. – CodeTalk Jan 14 '15 at 15:39
  • 2
    Put the error reporting at the very top of your page. – vaso123 Jan 14 '15 at 16:43