I wrote a PHP script with Netbeans

I’ve got a Drupal install with just under 300 users. I needed a certain type of node created for each user. Didn’t feel like logging in as each one and creating a node. Didn’t feel like looking for a module either for a few reasons. Decided I’d write my own little script to handle it. The tough part was just making sure I had good logic figured and a solid understanding of what Drupal did when it made a node. It ended up involving 3 tables which isn’t too bad.

I have a little, local Drupal install that I used to write and test. Today I made a copy of the production environment, on the remote server and tried it out. It didn’t work. It ran and made the nodes but nothing showed up. It made me sad inside.

It took me a little poking around to figure it out. The nodes contain a bunch of Arabic in the production environment, but not in my test. My script was not handling the unicode correctly and a single line added to my script fixed it.

This is what I had:



$link = mysql_connect('localhost', 'drup_user', 'drupal')
or die('Could not connect: ' . mysql_error());
echo "Connected successfully. \n";
mysql_select_db('nmsdemov3') or die('Could not select database');



And this is what fixed my problem:



$link = mysql_connect('localhost', 'drup_user', 'drupal')
or die('Could not connect: ' . mysql_error());
echo "Connected successfully. \n";
mysql_select_db('nmsdemov3') or die('Could not select database');
mysql_set_charset('utf8',$link);



As mentioned, I wrote the script in Netbeans. I’m not sure if I liked that experience or not. A full IDE might be a bit of overkill for a single file script. But it wasn’t horrible or anything. I may keep doing it just to spend more time in that environment so that I learn it better for the other stuff I do.

Leave a Reply

Your email address will not be published. Required fields are marked *