Archive

Archive for the ‘MySQL’ Category

get DB handler in CodeIgniter for stand-alone Libraries

February 11th, 2010

We were working on a project where some developers were working with CI and were developing libraries there, and some developers were developing stand-alone libraries. But both groups were working on the same project.

At some point we needed all those stand-alone libraries to beĀ  used in CI as well.
For common code it’s not a big deal, the only problem which took a little bit of time to figure out was using the DataBase. We didin’t want to make new DB connections, so how could we use the current connection, inside an stand-alone code.

The answer is pretty easy, CI’s DB class has a non-documented attribute which returns back the DB handler.

$this->db->conn_id

or if you have multiple DB cnnections that would be :

$this->dbr->conn_id;

$this->dbw->conn_id;

and then you can easily pass the DB connection to regular mysql_query function like this :

mysql_query ( string $query [, resource $link_identifier ] );

and as an example :

mysql_query ( ‘SELECT * FROM `table1`’, $this->dbr->conn_id );

CodeIgniter, General, MySQL , , ,

who is “Definer” in terms of MySQL

May 21st, 2009

Today I was playing with our database settings and trying to grant/ cut permissions of users from the development DB and production DB, changing passwords and so on.
Using our primitive hosting’s control panel I wanted to remove the main production DB user from Development DB, which I ended up loosing the user completely.
I created a new user/pass and in few seconds I changed the configurations. Evertyhing looked fine till I got a phone call fromĀ  by boss and I found that something is missing and not working properly.

The problem was on one of our scripts and the error was :

The user specified as a definer : (’no_such_user’@'no_such_host’) is invalid or unregistered

And thank to our primitive control panel, I was not able to recreate the user as it contains “_” [underscore] in the username.

All the settings were fine and I was wondering what’s causing the problem. At first rush I thought that it could be a cache, as I had requested recently to have xcache on our server.

But it wasn’t the case. The error was much more stupid than even one can imagine. That specific script uses a stored procedure to insert / fetch data to/from MySQL. The user who had created the sp was the one who was deleted. And that was the problem. The term “Definer” in terms of MySQL is the one who creates the stored procedure and for the stored procedure to be executed that user must exists.

A quick solution for that was dropping the old stored procedure and re-create it while logged in to MySQL with the new user.

Voila, it solved our issue. Not the best solution but at least I figured out what “Definer” means and it must exists when a sp is being called.

MySQL, SQL, Server , ,

WAMP server: right-click and select your version

April 27th, 2009

Have you ever been in a situation that you need to install PHP5 to have one application which is spcifically written in PHP5 and you have also some legacy applications which are written in PHP4 and are not compatible with PHP5 but you want to have them both.

I used to hate all those software bundles installing Apache/MySQL/PHP for you easily. I prefered to have them separately installed by myself to have more control over it. But considering WAMP server with an amazing feature of having many versions of Apache/MySQL/PHP and just switch from one to another by right-clicking and selecting it, is awesome.

I’ll definitely consider it for my local machine. [First need to be done with my exam on Wednesday]

Apache, General, MySQL, PHP, Server , , , , ,