*** lex.c.orig Thu Aug 28 16:21:32 1997 --- lex.c Wed Jan 14 18:17:30 1998 *************** *** 339,344 **** --- 339,345 ---- { "solid_close", INTFUNC1,Solid_close }, { "sybsql_seek",INTFUNC1,SybsqlSeek}, { "phpshowpool",INTFUNC0,ShowPool }, + { "pg_connect2", INTFUNC6,PGconnect2 }, { NULL,0,NULL } }, { { "getlastemail", INTFUNC0,GetLastEmail }, /* 12 */ *** pg95.c.orig Wed Jan 14 18:13:01 1998 --- pg95.c Wed Jan 14 19:25:38 1998 *************** *** 721,726 **** --- 721,934 ---- #endif } + void PGconnect2(void) { + #ifdef HAVE_LIBPQ + Stack *s; + PGconn *new_conn; + char *host=NULL; + char *port=NULL; + char *options=NULL; + char *tty=NULL; + char *db=NULL; + char *user=NULL; + char *passwd=NULL; + char *temp; + int j; + int len = 0; + char *connect_string; + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + user = estrdup(1,s->strval); + if (!(temp = strchr(user,(int)'/'))) { + Error("No user/passwd delimiter / found in pg_connect2"); + Push("0", LNUMBER); + return; + } + *temp = '\0'; + len += strlen(user) + strlen("user=") + 1; + + if (strlen(temp+1) == 0) { + Error("No passwd supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + passwd = estrdup(1,temp+1); + len += strlen(passwd) + strlen("password=") + 1; + } + + else { + Error("No user/passwd pair supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + db = estrdup(1,s->strval); + len += strlen(db) + strlen("dbname=") + 1; + } + else { + Error("No database name supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + if (strlen(s->strval)) { + tty = estrdup(1,s->strval); + len += strlen(tty) + strlen("tty=") + 1; + } + } + else { + Error("No tty name supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + if (strlen(s->strval)) { + options = estrdup(1,s->strval); + len += strlen(options) + strlen("options=") + 1; + } + } + else { + Error("No options string supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + if (strlen(s->strval)) { + port = estrdup(1,s->strval); + len += strlen(port) + strlen("port=") + 1; + } + } + else { + Error("No port number supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + s = Pop(); + if (!s) { + Error("Stack error in pg_connect2"); + Push("0", LNUMBER); + return; + } + if (s->strval) { + if (strlen(s->strval)) { + host = estrdup(1,s->strval); + len += strlen(host) + strlen("host=") + 1; + } + } + else { + Error("No host name/address supplied in pg_connect2"); + Push("0", LNUMBER); + return; + } + + len += strlen("authtype=password"); + + connect_string = emalloc(1,len+1); + *connect_string = '\0'; + + if (host){ + strcat(connect_string,"host="); + strcat(connect_string,host); + strcat(connect_string," "); + } + if (port){ + strcat(connect_string,"port="); + strcat(connect_string,port); + strcat(connect_string," "); + } + if (options){ + strcat(connect_string,"options="); + strcat(connect_string,options); + strcat(connect_string," "); + } + if (tty){ + strcat(connect_string,"tty="); + strcat(connect_string,tty); + strcat(connect_string," "); + } + if (db){ + strcat(connect_string,"dbname="); + strcat(connect_string,db); + strcat(connect_string," "); + } + if (user){ + strcat(connect_string,"user="); + strcat(connect_string,user); + strcat(connect_string," "); + } + if (passwd){ + strcat(connect_string,"password="); + strcat(connect_string,passwd); + strcat(connect_string," "); + } + strcat(connect_string,"host="); + strcat(connect_string,host); + strcat(connect_string," "); + strcat(connect_string,"authtype=password"); + + new_conn = PQconnectdb(connect_string); + if ((new_conn == NULL) || (PQstatus(new_conn) == CONNECTION_BAD)) { + Error("Could not connect to database (%s)", PQerrorMessage(new_conn)); + temp = (char*) emalloc(1,2); + sprintf(temp, "0"); + } + else + { + j = pg_add_conn(new_conn); + temp = (char*) emalloc(1,(j%10)+3); + sprintf(temp, "%d", j); + + /* get and cache the type table */ + if (pgTypeRes == 0) + pg_type(new_conn, -2); + } + Push(temp, LNUMBER); + #else + Pop(); + Pop(); + Pop(); + Pop(); + Pop(); + Pop(); + Error("No postgres95 support"); + #endif + } + void PGclose(void) { #ifdef HAVE_LIBPQ Stack *s; *** php.h.orig Mon Jun 16 23:09:45 1997 --- php.h Wed Jan 14 18:19:07 1998 *************** *** 807,812 **** --- 811,817 ---- void PGexec(void); void PG_result(void); void PGconnect(void); + void PGconnect2(void); void PGclose(void); void PGnumRows(void); void PGnumFields(void);