1

I got problem about using use curl_init() on the same domain and server. I have 2 Laravel projects on same environment run with xampp (window). Project A is API use database name X(RDS) Project B call API use database name Y(MySql)

Example URL

Project A ww.example/project_a/

Project B ww.example/project_b/

Problem

Project B use curl_init() call API from Project A for get data from database X(RDS), but Project A try to find database X in MySql(Project B connection) and then error.

I already tried to make both project run on different server it can work. Do I have to config something?

Here .env of both

Project A

APP_NAME= A
APP_ENV=local
APP_KEY=XXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=rds
DB_HOST=rds_url
DB_PORT=3306
DB_DATABASE=X
DB_USERNAME=xx
DB_PASSWORD=xx

Project B

APP_NAME_B= B
APP_ENV_B=local
APP_KEY_B=YYYYYYYYYYYYY
APP_DEBUG_B=false
APP_LOG_LEVEL_B=debug
APP_URL_B=http://localhost

DB_CONNECTION_B=mysql
DB_HOST_B=127.0.0.1
DB_PORT_B=3306
DB_DATABASE_B=Y
DB_USERNAME_B=yy
DB_PASSWORD_B=yy

Curl

$curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => "http://ww.example/project_a/booking-box/get-data-by-api",
        CURLOPT_COOKIESESSION => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",          
        CURLOPT_HTTPHEADER => array(
                    //"authorization: ",
                    "cache-control: no-cache",
                    "content-type: Application/json"
                ),
                ));
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);

Error Because Project A can't find X in Mysql

 "SQLSTATE[HY000] [1049] Unknown database 'X' (SQL: select * from `...` where `...` = 1 limit 1)"

Also already try this but not work Two Laravel applications on the same server conflicting with one another

banku
  • 119
  • 6
  • what's the error ? where is your code using `curl_init()` ? – N69S Sep 26 '19 at 09:30
  • error from API side. It's just a error can't found table name... because database structure isn't same – banku Sep 26 '19 at 09:44
  • how can we help you if we dont even know what's the error is exactly ? are we supposed to throw generic solution until one fixes your issue ? – N69S Sep 26 '19 at 10:26
  • Sorry I add some information – banku Sep 26 '19 at 12:17
  • is your rds DB open for external connexion ? maybe there is an ip filter, try to connect to it via commands – N69S Sep 26 '19 at 13:27
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 02 '19 at 22:42

0 Answers0