Category: Programming

  • Homebrew PHP Upgrade: “configure: error: Cannot find libz”

    I was routinely upgrading my packages on Homebrew when I ran into the following error:

    $ brew upgrade
    ==> Upgrading 1 outdated package, with result:
    homebrew/php/php70 7.0.4
    ==> Upgrading homebrew/php/php70
    ==> Downloading https://php.net/get/php-7.0.4.tar.bz2/from/this/mirror
    Already downloaded: /Library/Caches/Homebrew/php70-7.0.4
    ==> ./configure --prefix=/usr/local/Cellar/php70/7.0.4 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7.0 --with-config-file-path=/usr/local/etc/php/7.0 --wi
    Last 15 lines from /Users/johnro/Library/Logs/Homebrew/php70/01.configure:
    checking for OpenSSL support... yes
    checking for Kerberos support... /usr
    checking whether to use system default cipher list instead of hardcoded value... no
    checking for krb5-config... /usr/bin/krb5-config
    checking for RAND_egd... no
    checking for pkg-config... no
    checking for OpenSSL version... >= 0.9.8
    checking for CRYPTO_free in -lcrypto... yes
    checking for SSL_CTX_set_ssl_version in -lssl... yes
    checking for PCRE library to use... bundled
    checking whether to enable the SQLite3 extension... yes
    checking bundled sqlite3 library... yes
    checking for ZLIB support... yes
    checking if the location of ZLIB install directory is defined... no
    configure: error: Cannot find libz
    

    Of course, I did the first thing I always do when running into an error, Google it! And I found this link that suggested running the following:

    $ xcode-select --install

    After that,

    $ brew upgrade

    ran fine.

  • Apache Drill: Error Starting Drill in Embedded Mode

    Apache Drill: Error Starting Drill in Embedded Mode

    I’ve been checking out Apache Drill and everything was fine, until today. I tried running Drill in embedded mode, per usual, when I ran into the following exception:

    Error: Failure in connecting to Drill: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010 (state=,code=0)
    
    java.sql.SQLException: Failure in connecting to Drill: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010
    
    at org.apache.drill.jdbc.impl.DrillConnectionImpl.<init>(DrillConnectionImpl.java:159)
    
    at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)
    
    at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)
    
    at net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)
    
    at org.apache.drill.jdbc.Driver.connect(Driver.java:72)
    
    at sqlline.DatabaseConnection.connect(DatabaseConnection.java:167)
    
    at sqlline.DatabaseConnection.getConnection(DatabaseConnection.java:213)
    
    at sqlline.Commands.connect(Commands.java:1083)
    
    at sqlline.Commands.connect(Commands.java:1015)
    
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
    at java.lang.reflect.Method.invoke(Method.java:606)
    
    at sqlline.ReflectiveCommandHandler.execute(ReflectiveCommandHandler.java:36)
    
    at sqlline.SqlLine.dispatch(SqlLine.java:742)
    
    at sqlline.SqlLine.initArgs(SqlLine.java:528)
    
    at sqlline.SqlLine.begin(SqlLine.java:596)
    
    at sqlline.SqlLine.start(SqlLine.java:375)
    
    at sqlline.SqlLine.main(SqlLine.java:268)
    
    Caused by: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010
    
    at org.apache.drill.exec.client.DrillClient$FutureHandler.connectionFailed(DrillClient.java:448)
    
    at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:237)
    
    at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:200)
    
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
    
    at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:603)
    
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:563)
    
    at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:424)
    
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:214)
    
    at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
    
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:120)
    
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
    
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    
    at java.lang.Thread.run(Thread.java:745)
    
    Caused by: java.util.concurrent.ExecutionException: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010
    
    at io.netty.util.concurrent.AbstractFuture.get(AbstractFuture.java:47)
    
    at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:213)
    
    ... 12 more
    
    Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010
    
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:212)
    
    ... 6 more

    (more…)

  • PHP: Connect to SQL Server Database on Linux (and Mac OS X)

    Microsoft SQL Server
    Microsoft SQL Server

    I have used PHP to connect to SQL Server plenty of time, and every time I would use the SQLSRV extension. The problem with that is, PHP’s SQLSRV extension is only available for Windows servers. Which wasn’t a problem for me because I would normally develop PHP on Windows machines. It wasn’t until recently I needed SQL Server access on a Linux machine.

    It wasn’t as straightforward as I had hoped, and it certainly did not help to learn that the MSSQL PHP extension was removed in version 7.0, which took me a few hours to discover. I am writing this post in hopes that I save some people a few hours of pain, including my future self.
    (more…)

  • Installing Microsoft SQL Server Data Tools – Business Intelligence for Visual Studio 2013: Rule “Same architecture installation” failed??

    SSDTFailed
    So I had to install Microsoft SQL Server Data Tools – Business Intelligence for Visual Studio 2013 today, and was greeted with the above error. Based on the error, I assumed I had SQL Server 2014 x64 installed and I somehow needed SSDT for x64 and not x86. Funnily enough, the installation page suggests both x64 and x86 architectures are supported. I was frantically searching for a x64 installation.

    Thanks to a StackOverflow post:

    As the others have said, there is only a 32 bit version.

    The important thing is, if you’re running an x64-based SQL instance (64-bit), make sure to select “New Instance” on the Installation Type page, and NOT “Add features to an existing instance”. Not doing so will cause it to error out.

    I was selecting “Add features to an existing instance” thinking “New Instance” meant installing a new SQL Server fresh again, like most people would.

  • SQL Server: Taking Advantage of Transactions

    I won’t go in depth about SQL Server transactions, but rather what you can do to apply destructive changes safely, like deleting records or updating them. It’s highly advised that direct queries don’t get run on production databases but there are situations where that is required.

    (more…)

  • PHP: How to array_merge Without Losing Numeric Keys

    PHP function array_merge is nice in that you can easily merge one (or more) arrays into a single array with a single call of the function. The keys are retained, but only if they’re not numeric keys(!).

    E.g.

     "hi");
    $array2 = array(3 => "data");
    $result = array_merge($array1, $array2);
    ?>
    
    Result:
    Array
    (
        [0] => hi
        [1] => data
    )

    Perhaps this is the behavior you want. But what if you want to retain the original numeric keys?

    (more…)

  • PHP: sqlsrv problems with UTF-8 values? Set your CharacterSet option!

    Are you banging your head trying to figure out how to convert a seemingly invalid UTF-8 value into a valid one? You might be surprised to know that the problem isn’t how PHP interprets the characters, but rather a database connection issue. If the UTF-8 value in question looks valid in the database but does not look right when displayed on a web page, that could mean your database connection settings are not set correctly.
    (more…)

  • PHP: Importing an SQL file via PHP script

    Trying to import an SQL file using PHP? Most people will tell you that using PHP function shell_exec to run the MySQL client is your best bet, but what if you simply can’t do it that way? The solution is quite simple, actually, and doesn’t require programming skills beyond the basic file parsing and query executing.
    (more…)

  • Sorting your photo collection by date the PHP way

    Ever wanted to sort your photo collection in the order by date taken? Can’t find the right program that will do it for you? I decided that I had a large enough collection myself to warrant organizing, but I could not find a program that can organize it the way I want it. I have always wanted the photos to be sorted by the date taken and grouped by the year, so I decided to create a short script for myself.
    (more…)

  • SQL Server: Selecting multiple rows into a single row with multiple columns

    I ran into a problem writing a query today, and took the time to find the solution, so I thought I should share this with anyone who has the same problem. This solution should only work for SQL Server version 2005 and above.
    (more…)