Menu
SuiteCRM Pull Request Party hosted by SalesAgility
Welcome, Guest
Username: Password: Remember me

TOPIC: Import data from my database

Import data from my database 5 months 1 week ago #75366

  • Neon_Duck
  • Neon_Duck's Avatar
  • Offline
  • Junior Member
  • Posts: 24
  • Thank you received: 1
  • Karma: 0
Hi,

I tried many things but I don't know what to do.
I created all the tables I needed in my suitecrm database and inserted all of my data. That works.

But now I want import the data into my suitecrm and get the relationships but that didn't work.

I connect with my database:


$servername="localhost";
$username="<secret>";
$password="<secret>";
$dbname="<secret>";

$db=new mysqli($servername, $username, $password, $dbname);

if($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}


and when I try to make this:

[...]

$sfrc_query = "SELECT * from {$sfrc_table} ";
$sfrc_result=$db->query($sfrc_query);
while($item=$db->fetchByAssoc($sfrc_result)){

[...]

I just get the error:

PHP Fatal error: Uncaught Error: Call to undefined method mysqli::fetchByAssoc()

and when I comment the first one out I just get:

PHP Fatal error: Uncaught Error: Call to a member function query() on null

Changing the $db to $GLOBALS["db"] didn't work.

I'm executing my script in the linux terminal with "php -f 'script name' ".

What I have to change? Do I need to execute it somewhere else?

I used the second script from: community.sugarcrm.com/thread/19736

It would be nice if someone could help me :)
Last Edit: 5 months 1 week ago by Neon_Duck.
The administrator has disabled public write access.

Import data from my database 5 months 1 week ago #75389

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 9857
  • Thank you received: 1469
  • Karma: 349
Hi

is this your attempt to connect to the original database (the source of data) or to the SuiteCRM database (the destination)?

If it's the source, do you have a lot of complex data with relationships etc, or could you be better off just exporting a table to CSV and then importing?

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Import data from my database 5 months 1 week ago #75411

  • Neon_Duck
  • Neon_Duck's Avatar
  • Offline
  • Junior Member
  • Posts: 24
  • Thank you received: 1
  • Karma: 0
Thank your for your answer.

I already have imported my csv files into my suitcrm database. Now I want to parse the data from the salesforce tables to the respective suitcrm db tables to see them with the relationships in the UI.

There is a lot of data to export from the database to suitcrm.
Last Edit: 5 months 1 week ago by Neon_Duck.
The administrator has disabled public write access.

Import data from my database 5 months 1 week ago #75417

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 9857
  • Thank you received: 1469
  • Karma: 349
Here is an example of direct SQL access, in its simplest form:
  if (!defined('sugarEntry') || !sugarEntry) die ('Not a Valid Entry Point!');

  global $db;

  $query = "SELECT lead_source, sales_stage as stage, amount as total, user_name as user
            FROM opportunities
            LEFT JOIN users ON users.id = opportunities.assigned_user_id
            WHERE opportunities.deleted=0
            ";
  $result=$db->query($query,true);
  while( $row = $db->fetchByAssoc($result)) {
    echo $row['stage'], ": ", $row['total'], '<br/>';
  }

Please try to grab simple data from your input tables with this code, and see if it works.

Make sure you register your PHP file as an entrypoint first:
docs.suitecrm.com/developer/entry-points...ating_an_entry_point

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Import data from my database 5 months 1 week ago #75422

  • Neon_Duck
  • Neon_Duck's Avatar
  • Offline
  • Junior Member
  • Posts: 24
  • Thank you received: 1
  • Karma: 0
Do I need to execute my php scripts like an entry point?
Or how do I execute the scripts?
The administrator has disabled public write access.

Import data from my database 5 months 1 week ago #75426

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 9857
  • Thank you received: 1469
  • Karma: 349
Since you're using SuiteCRM classes and code, if you don't register the entrypoint your code will be excluded for security reasons.

It's easy - just register the entrypoint, and your code will run "inside" SuiteCRM, then you can use all the power of Beans etc for your import.

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.
The following user(s) said Thank You: Neon_Duck

Import data from my database 5 months 1 week ago #75512

  • Neon_Duck
  • Neon_Duck's Avatar
  • Offline
  • Junior Member
  • Posts: 24
  • Thank you received: 1
  • Karma: 0
Okey, I'll try it with my code. Thank you Sir!
The administrator has disabled public write access.
Time to create page: 0.032 seconds
Powered by Kunena Forum