Connect to Sharepoint Database via PHP

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

Is there a way I can do this?

Thank you at advanc. Any help is appreciated.

+8
database php sharepoint connection
source share
7 answers

You should consider using the Camelot PHP tools for SharePoint, a well-documented php framework for the Camelot XML format, specifically designed 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 in the field that can reach the SharePoint server, it can be the same server as the SharePoint server, and then install the Integration Toolkit on the same server as Connector. Configure the integration service included in the integration toolkit (follow the instructions), and then you are done. Websites also have a few instructions.

Using this method, you can talk to SharePoint lists and libraries through the API using common SQL queries; the mssql database is never used.

Selecting data from SharePoint using SQL

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

Select data from SharePoint by list and view name

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

Paste data into SharePoint using 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('Ymd H:i:s') ."',0.95)", 'method' => 'ExecuteNonQuery', 'connection_name' => 'SharePointConnection1' )); 

There are also stored procedures that will help you with some operations, such as advanced document library processing.

Upload file

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

Upload file

 $args = array( "file" => $_FILES, "listName" => 'Shared Documents', "folder" => 'Folder/', "connection_name" => 'SharePointConnection2' ); $UploadFile = new CamelotUploadFile($args); 
+5
source share

I highly recommend using SharePoint WebServices instead ... if there are good reasons (e.g. performance), I would not touch the database. Quote from this answer:

  • This is not fully supported by the agreement that you agreed when you installed SharePoint.
  • Your requests do not guarantee operation after applying any patches or service packs for SharePoint with Microsoft may change the database schema at any time.
  • A direct database query can additionally load the server load and, therefore, performance issues.
  • Direct SELECT statements to the database accept common read locks at the transaction level by default, so that your user queries may cause deadlocks and therefore stability issues.
  • Your user queries may result in incorrect data retrieval.

If you want to know more about why you should not query the database, here is a really great article

SharePoint WebService request with PHP

+6
source share

It is just a database - if you have the server / database name and the corresponding permissions, you cannot stop anything. However, the scheme is very attractive, so figuring out what you need can be difficult - depending on what you really want to do, you might be better off using web services to access Sharepoint OM.

If you want to write directly to the database - do not do this. There is no practical way to do this without going deeper down the line, and support cannot help you.

+1
source share

The Sharepoint database is nothing but MS SQL Server. If you know the name of the server, you can connect to it in the same way as to how you can connect to the MSSQL server with PHP.

0
source share

The easiest way to get SharePoint data from PHP is probably through the REST API .

0
source share

I used this in the API to connect my PHP web application to SharePoint and transfer data from PHP to SharePoint, it worked 100% for me:

Instructions for use :

Installation

Download the WSDL file for the SharePoint lists you want to interact with. This can usually be obtained at: sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL

If you are using composer, just add thybag / php-sharepoint-lists-api to your composer.json and run composer.

  { "require": { "thybag/php-sharepoint-lists-api": "dev-master" } } 

If you are not using composer, you can manually download a copy of the SharePoint API files and include the top class "SharePointAPI.php" in your project.

Create a SharePointAPI Object

To use the PHP SharePoint List APIs, you need a valid user / service account with the permissions for the required list.

For most SharePoint installations, you can create a new instance of the API using:

  use Thybag\SharePointAPI; $sp = new SharePointAPI('', '', ''); 

If your installation requires NTLM authentication, you can use:

  use Thybag\SharePointAPI; $sp = new SharePointAPI('', '', '', 'NTLM'); 

SharePoint Online users should use:

  use Thybag\SharePointAPI; $sp = new SharePointAPI('', '', '', 'SPONLINE'); 

All methods return an array by default. SetReturnType can be used to indicate that results should be returned as objects.

Reading from the list.

To return all items from a list, use either

  $sp->read(''); 
 or 
  $sp->query('')->get(); 

To return only the first 10 items from a list, use:

  $sp->read('', 10); 

or

  $sp->query('')->limit(10)->get(); 

To return all items from a list where Smith's last name is, use:

  $sp->read('', NULL, array('surname'=>'smith')); 

or

  $sp->query('')->where('surname', '=', 'smith')->get(); 

List request

You can use the query method when you need to specify a complex query that can be easily determined using read methods. Queries are built using a number of (hopefully expressive) pseudo SQL methods.

For example, if you want to request a list of pets and return all dogs under 5 years of age (sorted by age), you can use them.

 $sp->query('list of pets')->where('type','=','dog')->and_where('age','sort('age','ASC')->get(); 

If you want to get the first 10 animals that were cats or hamsters, you can use:

  $sp->query('list of pets')->where('type','=','cat')->or_where('type','=','hamster')->limit(10)->get(); 

If you need to return 5 items, but including all the fields contained in the list, you can use. (pass false to all_fields to enable hidden fields).

  $sp->query('list of pets')->all_fields()->get(); 

If you have a CAML set for a specific extended request that you want to execute, you can pass it to the request object using:

  $sp->query('list of pets')->raw_where('Hello World')->limit(10)->get(); 

Add to list

To add a new element to the list, you can use the "write", "add" or "insert" method (all functions are identical). Creating a new entry in the list with column names, last name, age and phone may look like this:

  $sp->write('', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' )); 

You can also start several write operations using:

  $sp->writeMultiple('', array(array('forename' => 'James'),array('forename' => 'Steve'))); 

Line editing

To edit a line you need to have its identifier. Assuming the above line had ID 5, we could change Bob's name to James with:

  $sp->update('','5', array('forename'=>'James'));/code> 

As with the write method you can also run multiple update operations together by using:

  $sp->updateMultiple('', array( array('ID'=>5,'job'=>'Intern'),array('ID'=>6,'job'=>'Intern'))); 

When using updateMultiple, each element MUST have an identifier.

Delete lines

To delete a line, an identifier is required, as well as a list name. To delete an entry for James with id 5, you should use:

  $sp->delete('', '5'); 

If you want to delete several records at once, the ID array can also be passed to several delete methods

  $sp->deleteMultiple('', array('6','7','8')); 

Helper Methods

The PHP SharePoint API contains several helper methods that make it easy to ensure that certain values ​​have the correct format for some special SharePoint data types.

dateTime You can pass a text date to the DateTime method

  $date = \Thybag\SharepointApi::dateTime("2012-12-21"); 

Or Unix timestamp

  $date = \Thybag\SharepointApi::dateTime(time(), true); 

Problem finding

Unable to find wrapper "https"

If you get this error, it usually means that php_openssl (needed to curl https URLs) is not enabled on your web server. On many local web servers (such as XAMPP), you can simply open the php.ini file and uncomment the php_openssl line (i.e. delete; in front of it).

Note. If you are using SharePoint Online and are having SSL errors, install the latest version that has been changed from SSL v3 to TLS for SharePoint online connections.

Add this line to your composer.json file

  thybag / php-sharepoint-lists-api: dev-develop 

You can perform a CRUD operation (create / read / update / delete) using the above SharePoint API.

Link URL link: https://github.com/thybag/PHP-SharePoint-Lists-API

0
source share

I use this API to work great! But I have a problem:

 $php_data = $sp->read('list_name'); var_dump($php_data); 

result:

 array(3) { [0]=> array(5) { ["grey"]=> string(3) "aaa" ["black"]=> string(3) "bbb" ["blue"]=> string(3) "ccc" ["green"]=> string(3) "ddd" ["yellow"]=> string(3) "eee" ["brown"]=> string(3) "fff" } [1]=> array(5) { ["grey"]=> string(3) "ggg" ["black"]=> string(3) "hhh" ["blue"]=> string(3) "iii" ["green"]=> string(3) "jjj" ["yellow"]=> string(3) "kkk" ["brown"]=> string(3) "lll" } [2]=> array(5) { ["grey"]=> string(3) "mmm" ["black"]=> string(3) "nnn" ["blue"]=> string(3) "ooo" ["green"]=> string(3) "ppp" ["yellow"]=> string(3) "qqq" ["brown"]=> string(3) "rrr" } } 

I do not know how to build my request in order to have:

 array(3) { [0]=> array(2) { ["grey"]=> string(3) "aaa" ["blue"]=> string(3) "ccc" } [1]=> array(5) { ["grey"]=> string(3) "ggg" ["blue"]=> string(3) "iii" } [2]=> array(5) { ["grey"]=> string(3) "mmm" ["blue"]=> string(3) "ooo" } } 

I block ... thanks in advance for your help

0
source share

All Articles