Connect to Sharepoint Database through PHP

15,736

Solution 1

You should consider using the Camelot PHP Tools for SharePoint, it's a well documented php framework for the Camelot XML format specially constructed for SharePoint lists.

Documentation and download

You will also need the Camelot SharePoint Integration Toolkit, http://camelottoolkit.codeplex.com/ and the Camelot .NET Connector (http://www.bendsoft.com/net-sharepoint-connector/).

Install the Connector on a box that can reach the SharePoint server, this may be the same server as the SharePoint server, then install the Integration Toolkit on the same server as the Connector. Set up the integration service that is included in the integration toolkit (follow the instructions) and then you are done. There are a few instruction videos on the websites as well.

The upsides of using this is that you will be able to talk to SharePoint lists and libraries through the API by using common SQL queries, the underlying mssql database is never used.

Selecting data from SharePoint with SQL

$SharePointQuery = new SharePointQuery(array(
    'sql' => "SELECT * FROM Tasks WHERE ID > 10",
    'connection_name' => 'SharePointConnection1'
));

Selecting data from SharePoint by list and view name

$SharePointQuery = new SharePointQuery(
    array(
        'listName' => 'Tasks',
        'viewName' => 'All Tasks',
        'includeAttachements' => false,
        'connection_name' => 'SharePointConnection1',
        'columns' => ''
    )
);

Insert data in SharePoint with SQL and SharePointNonQuery

$SharePointNonQuery = new SharePointNonQuery(array(
    'sql' => "INSERT INTO Tasks (Title,AssignedTo,Status,Priority,DueDate,PercentComplete) VALUES ('Test task from PHP',1,'In Progress','(1) High', '".  date('Y-m-d H:i:s') ."',0.95)",
    'method' => 'ExecuteNonQuery',
    'connection_name' => 'SharePointConnection1'
));

There are also stored procedures to help you with some operations, like advanced handling of document libraries

Download a file

$download = new CamelotDownloadFile(array(
    "file" => $_GET["file"],
    "listName" => 'Shared Documents',
    "connection_name" => 'SharePointConnection1'
));

$download->download_file();

Upload a file

$args = array(  
    "file" => $_FILES,
    "listName" => 'Shared Documents',
    "folder" => 'Folder/',
    "connection_name" => 'SharePointConnection2'
); 

$UploadFile = new CamelotUploadFile($args);

Solution 2

i highly recommend using the SharePoint WebServices instead... unless there are valid reasons (i.e. performance) i would not touch the database. Quote from this answer:

  1. This is completely unsupported by the EULA you agreed to when you installed SharePoint.
  2. Your queries are not guaranteed to work after applying any patches or service packs to SharePoint since Microsoft could change the database schema anytime.
  3. Directly querying the database can place extra load on a server and hence performance issues.
  4. Direct SELECT statements against the database take shared read locks at the default transaction level so your custom queries might cause deadlocks and hence stability issues.
  5. Your custom queries might lead to incorrect data being retrieved.

If you want to know more about why you shouldn't query the database, here is a really great article

Query A SharePoint WebService with PHP

Solution 3

It's just a database - as long as you have the name of the server/database and the proper permissions, there is nothing that can stop you. However - the schema is pretty involved, so figuring out from there what you need can be tricky - depending on what you really want to do, you may be better off using the web services to access the Sharepoint OM.

In case you want to write to the database directly - don't. There is no practical way to do that without getting yourself into deep trouble farther down the line, and support won't be able to help you out.

Share:
15,736

Related videos on Youtube

Mo3z
Author by

Mo3z

Updated on June 04, 2022

Comments

  • Mo3z
    Mo3z almost 2 years

    I am not familiar with Sharepoint. I would like to query or read Sharepoint database using PHP.

    Is there a way I can do that?

    Thank you in advanc. Any help is greatly appreciated.

    • Thilo Savage
      Thilo Savage over 12 years
      linkTry this
  • Ryan
    Ryan over 12 years
    MS policy on direct SharePoint database access is... Don't. msdn.microsoft.com/en-us/library/bb861829(v=office.12).aspx you will be much much better off using the Web Services interface - see @Andreas's answer.