SQLSTATE[HY000]: General error – using php/pdo mysql stored procedures (sp)

I spent many hours last night trying to figure out why I was getting a fatal error: ‘SQLSTATE[HY000]: General error 0’ in my code and finally figured it out but first my environment. I’m using Zend Server CE running php 5.3.0, zend framework 1.9.0 and mysql 5.1.32. I should have tested this bug without the zend framework to make sure it’s not specific to zf (I don’t think it is) but I’m feeling lazy so I’ll let someone else try it out.

My code works as follows. I have a php class that calls a stored procedure which will take in an id, return a record set (if found) and will also return 2 out variables. While it was returning a record set everything was working perfectly fine. When I tried passing an invalid id, nothing was being returned and my code would keep giving me the ‘SQLSTATE[HY000]: General error 0’ (very helpful error indeed…).

The issue ended up being the way I had my stored procedure coded. I would first check to see if the id passed was valid, if so I would select the data else I would set my out vars to some value and do nothing else. For some reason, because I wasn’t returning a select, my code would blow up. In the mysql query browser, my stored procedure worked fine and my second select to get the out vars was working correctly. But php didn’t like it one bit. I tried forcing a select in my stored procedure in the invalid id section and then everything worked fine again. This sounds a bit confusing so here is the way I can replicate this. Continue reading “SQLSTATE[HY000]: General error – using php/pdo mysql stored procedures (sp)”

Creating RSVP in PHP/MySQL w/ Zend Framework

This post is to share the php/zend framework code I used to create an rsvp for my wedding site. I’m not going into all the details since that would take too long ;p but all the code is available if you want to use it. This was created using the zend framework version 1.7.

So I’m getting married in two month and for our wedding my fiancee and I decided to create a website for our guests. The site includes information such as location, time, links to registries, maps, and a section to rsvp. The site was made by my fiancee in html and css. When she was done, I ported it over to zend framework and started creating the rsvp section which I’ll describe next. You can view the finished wedding site here:

RSVP Page

http://www.joeyrivera.com/wedding

Continue reading “Creating RSVP in PHP/MySQL w/ Zend Framework”

Using MySQL Stored Procedure IN/OUT and Recordset w/ PHP

Note: The code below will not work on all environments. I’m using php 5.2.6 with mysql driver 5.0.18.

In a previous post:
http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/

I explained how to use MySQL stored procedures with different db adapters such as mysql, mysqli, and pdo in PHP. In those examples, I demonstrated calling a sp with in/out variables and calling a stored procedure that returns a recordset. One of the comments I received was a person asking how to call a stored procedure that uses in/out parameters as well as returns a recordset. It’s not much different and here’s how.

The trick is to combine both methods in one. Here’s an example of what the stored procedure looks like:

DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`get_users` $$
CREATE PROCEDURE `get_users`(
IN firstName VARCHAR(100),
OUT totalUsers INT
)
BEGIN
SELECT COUNT(*)
INTO totalUsers
FROM users
WHERE first_name = firstName;
SELECT *
FROM users
WHERE first_name = firstName;
END $$
DELIMITER ;

Continue reading “Using MySQL Stored Procedure IN/OUT and Recordset w/ PHP”

Sony’s Motion Controller for PS3

Soon after Microsoft showed off project Natal, Sony introduced their own motion controllers they’ve been working on. Both seem very cool and just from watching these videos it seems to me that the Microsoft technology is more sophisticated but the Sony controllers would be more fun to play with. And like they said in the video below, sometimes it feel more natural to push a button.

 

Microsoft Project Natal for Xbox 360 looks neat

I must say I’m very impressed with what I’m seeing. Microsoft announced Project Natal at E3 and it’s a control/camera that detects sound and motion for the Xbox 360 so the user can play a game without ever holding a remote control. It’s easier to understand through these videos:

And here is a bit more info:
http://e3.gamespot.com/story/6210641/microsofts-project-natal-3d-camera-system

I personally don’t own a console but am very eager to try this one out.

EQ vs IQ: Emotional Intelligence (also know an EI or EQ)

Ever talked to a neighbor that won’t stop talking no matter how many hints you give that you want to leave? Are you giving the right clues? Ever talked to people that don’t care what you have to say and only want to tell you about themselves? Ever talked to someone at work that snapped at you for no reason? Did you notice them before to see if they seemed stressed or were having a bad day?

If you aren’t familiar with Emotional Intelligence I recommend you read some more about it. I recently learned about EQ at a work seminar and thought it’s a great concept that others should know about as well. Here’s are a couple resources:

http://en.wikipedia.org/wiki/Emotional_intelligencehttp://www.time.com/time/classroom/psych/unit5_article1.html

If you like psychology you will probably enjoying learning more about this.

Taken from the wiki page:

“The model introduced by Daniel Goleman [16] focuses on EI as a wide array of competencies and skills that drive leadership performance. Goleman’s model outlines four main EI constructs:[1]

Self-awareness — the ability to read one’s emotions and recognize their impact while using gut feelings to guide decisions.

Self-management — involves controlling one’s emotions and impulses and adapting to changing circumstances.

Social awareness — the ability to sense, understand, and react to others’ emotions while comprehending social networks.

Relationship management — the ability to inspire, influence, and develop others while managing conflict.”

Some of you may find some of this common sense but others may not. Why is this important? Because even the smartest person in the world (IQ) will have problems succeeding if he/she can’t manage their emotions or the way they interact and are perceived by others (EQ). I think the more understanding a person has of EQ, the easier life becomes. There are various situations that can be avoided or easily overcome just by paying attention causing less unnecessary stress.

Here is an example of where I think I use EQ relating to technology. When I go to speak to a person about say coding, I have to ask myself – “Do I know this person and if so, how tech savy are they?”. Based on that answer, I’ll adjust the way I speak to this person and use wording and or acronyms that I think this person would understand. If I don’t know this person and don’t know enough of their background to guesstimate, I’ll start talking to this person in a very general level (not too low to insult them if they are techy but not too detailed to lose them from the start if they aren’t) and based on the way this person interacts with me, see if I can go more tech details or if I need to get more generic and use none-tech related examples.

From then I also try to pay attention to see if this is a person that really truelly understands what I’m saying or is just knoding since many, including myself, are guilty to this. And finally based on the interaction or lack of I know if it’s time to change the subject or if we can keep going. All that just to have a conversation…

Have any similar experiences to share? Please do! We can all learn from each other.

AMF,XMLRPC,JSON,REST Zend Web Services Tutorial

I’ve been using the Zend for the last few months and I’m loving it. Here at work we were having a discussion about implementing some web services in the future so I decided to see what it takes to create some web services in PHP using Zend. I was pleasantly surprise (well not really surprised) that it was extremely quick and easy to get things up and running.

In this post, I’m going to explain how to create web services that can be accessed via AMF, XMLRPC, JSON, and REST using the Zend Framework. Hopefully these should cover most uses out there. I left SOAP out since I don’t really see myself using it any time soon. I will be communicating with a database as well to make the tutorial more informative. The db will consist of one table with information about courses such as mathematics courses.

I’m going to show you the final product first, hopefully to catch your attention so you’ll read the rest :). This is what the final product will look like. If you look at the following links in Chrome, do a view source to see the formatted response.

XMLRPC

One course:  http://www.joeyrivera.com/ZendWebServices/xml-rpc/course-info/abbr/math101/
All courses:  http://www.joeyrivera.com/ZendWebServices/xml-rpc/courses-info/

JSON

One course:  http://www.joeyrivera.com/ZendWebServices/json/course-info/abbr/math101/
All courses: http://www.joeyrivera.com/ZendWebServices/json/courses-info/

REST

One course:  http://www.joeyrivera.com/ZendWebServices/rest/course-info/?method=getCourseInfo&abbr=math102
All courses:  http://www.joeyrivera.com/ZendWebServices/rest/courses-info/?method=getCoursesInfo

AMF

One course:  http://www.joeyrivera.com/ZendWebServices/amf/course-info/abbr/math101
All courses:  http://www.joeyrivera.com/ZendWebServices/amf/courses-info/ Continue reading “AMF,XMLRPC,JSON,REST Zend Web Services Tutorial”

Calling a DLL with PHP

So here’s a quick post on calling dll’s in Windows using php. I have a dll that encrypts data in a certain format that we need for another process. So I need to pass the dll a string and it returns the encrypted string back.

I tried calling the dll using the COM class in code and was having issues until I realized I have to register the dll in windows first before I can call it using the COM class. To register a dll in windows you do the following in your command line:

REGSVR32 MyStuff.dll

Now that the dll is registered you can do the following to start accessing the dll:

$my_dll = new COM('MyStuff.Functions');

MyStuff is the dll name an/or id and Functions is the object inside the dll that we want to use. Now I call the method I need and pass the parameters:

$encrypted_text = null;
$input = 'This needs to be encrypted.';
$my_dll->EncryptString($input, $encrypted_text );

This is pretty much it. We instantiate the COM class with the dll and function I want. Then I call the method in the dll passing my text and it returns into my $encrypted_text var the encrypted text. I can now do my next process with the encrypted text like:

print $encrypted_text;

Dynamic PHP Images Tutorial

So I decided to play around with creating a dynamic php image to see how much work was involved and it’s actually pretty easy to do. In my case I wanted to solve the following problem.

I have a trip planned for a weekend coming up and I keep wanting to see what the weather is going to be like for that weekend. It seems everyday the weather.com forecast changes so I keep checking it on a daily basis. My options are

  1. go to the weather.com website, search for the zip code, then select view 10 day forecast or 
  2. create a quick and easy automated way of looking for this information as a graphic. 

Of course, I picked the latter. Here’s what we are about to create:


Continue reading “Dynamic PHP Images Tutorial”