Consider to add a row like:
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
before:
$ds=ldap_connect("localhost"); // must be a valid LDAP server!
if your ldap server if configured to not bind the 2nd version of ldap protocol...
(or add "allow bind_v2" in the server's ldap.conf).