2003-03-26 20:03:37 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder MySQL Implementation, $Date$, $Revision$
|
2006-01-17 18:56:30 +08:00
|
|
|
// Copyright (C) 2003, 2004, 2005, 2006 Philip Coombes
|
2003-03-26 20:03:37 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-09-07 23:39:44 +08:00
|
|
|
#include <string.h>
|
2003-03-26 20:03:37 +08:00
|
|
|
|
2003-05-16 18:27:41 +08:00
|
|
|
#include "zm.h"
|
2003-03-26 20:03:37 +08:00
|
|
|
#include "zm_db.h"
|
|
|
|
|
|
|
|
MYSQL dbconn;
|
|
|
|
|
2004-12-29 01:01:25 +08:00
|
|
|
void zmDbConnect()
|
2003-03-26 20:03:37 +08:00
|
|
|
{
|
|
|
|
if ( !mysql_init( &dbconn ) )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't initialise structure: %s", mysql_error( &dbconn ) );
|
2003-03-26 20:03:37 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2007-09-07 23:39:44 +08:00
|
|
|
char dbHost[256];
|
|
|
|
strncpy( dbHost, ZM_DB_HOST, sizeof(dbHost) );
|
|
|
|
if ( char *colon_ptr = strchr( dbHost, '/' ) )
|
|
|
|
{
|
|
|
|
*colon_ptr = '\0';
|
|
|
|
char *dbPort = colon_ptr+1;
|
|
|
|
if ( !mysql_real_connect( &dbconn, dbHost, ZM_DB_USER, ZM_DB_PASS, 0, atoi(dbPort), 0, 0 ) )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't connect to server: %s", mysql_error( &dbconn ) );
|
2007-09-07 23:39:44 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !mysql_real_connect( &dbconn, ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS, 0, 0, 0, 0 ) )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't connect to server: %s", mysql_error( &dbconn ) );
|
2007-09-07 23:39:44 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
}
|
2003-03-26 20:03:37 +08:00
|
|
|
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't select database: %s", mysql_error( &dbconn ) );
|
2003-03-26 20:03:37 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|